You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defvio_get_filelen(user_data):
# first try __len__(), if not available fall back to seek()/tell()try:
size=len(file)
exceptTypeError:
curr=file.tell()
file.seek(0, SEEK_END)
size=file.tell()
file.seek(curr, SEEK_SET)
returnsize
I suspect that the use of len() is a now obsolete artifact from the development in #1.
It was added there to seemingly support "streaming", but it turned out that this is not supported by the virtual IO call anyway.
Every supported file-like object must have the methods seek() and tell() anyway, so I think its superfluous to check with len() first.
Can we get rid of this remnant from the past?
I guess the cleaned-up version would look like this:
There are cases where len actually does the right thing.
Sure, it might do the right thing, that's not the point.
The question rather is: Is there a conceivable situation where len() does something that cannot be equally well done with seek() and tell()?
Since seek() and tell() are always available, I don't see any necessity for __len__().
The only reason I could theoretically think of, is if __len__() is more efficient than seek() + tell().
But this only happens if the implementation of the file-like object is broken.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Currently, we have this:
I suspect that the use of
len()is a now obsolete artifact from the development in #1.It was added there to seemingly support "streaming", but it turned out that this is not supported by the virtual IO call anyway.
Every supported file-like object must have the methods
seek()andtell()anyway, so I think its superfluous to check withlen()first.Can we get rid of this remnant from the past?
I guess the cleaned-up version would look like this:
I'm wondering why
get_filelenis even part of libsndfile's API, since it can be easily implemented withseekandtell...?