Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR extends
GuanoPy
to allow reading from any file-like object (one that implements methods seek, read, tell), not just via filename.This is important when the very large WAV file exists over a network and we want to extract GUANO metadata without downloading the entire sound data.
What I changed
GuanoPy.__init__
arg switched fromfilename
tofile
:file
is a string, opens the file by that name,file
is set, treat it as a file-like object (one that implements methods seek, read, tell).Add
filename
property that returns a string only if this GuanoPy object references a file by its filename. This is settable if you want to write a "new" file.Places that GuanoPy actually has to open the file (
_load
andwrite
methods), check if theself.filename
property is set (i.e. we have a string); if so, open it as usual, otherwise simply return the file-like object from acontextlib.nullcontext()
New test case to read a from file-like object: an already open file handle.