Check usage of seek() for non-seekable file formats#67
Conversation
|
That's bad. Is there any alternative? |
|
I checked in the documentation and the libsndfile repository. It seems that FLAC files are indeed seekable, but you can't I also remember using FLAC files a lot with the array interface and never experienced any problems. Would it be possible that you are experiencing the above bug? |
|
No, it works fine in The problem I described happens in |
|
Oh, I see. The same happens on 1.0.25/OSX. If you try to open a flac file in As for internal usages of
This requires |
I guess this would make sense, because Python throws an But then we should also raise an error in the other cases where I think we could just use our existing
To be consistent with Python, it should also raise an error.
This would mean we'd have to add a bit of code to avoid the error in the suggested changes of #60. if self.seekable():
self.seek(whatever)Alternatively, we could use |
|
I found out that seekability not only depends on the file format and open mode. A file is also non-seekable if it is a named pipe (see #68). There are probably even other situation where a file could be non-seekable, who knows ... I don't really know how to handle the |
|
If I remember correctly |
|
It's not available when using pipes, neither in read mode nor in write mode, see #68. |
|
Then I guess we'll have to throw an error if |
|
I added some commits which should implement the discussed changes. I re-factored some common functionality into two helper methods For testing the non-seekable stuff, I'm using the |
|
This turns out to be quite a bit more complicated than I thought. But I think your handling of these edge cases is very good and helpful! I'll think some more about the helper method names. In general, the naming of our helper methods is somewhat arbitrary. I'll have to think about this some more. |
|
Any ideas for better names? If not, I suggest to merge this and improve on the internal names later. |
Check usage of seek() for non-seekable file formats
Currently,
seek()is used at some points internally, e.g. when calculatingself.frameswithinwrite().This doesn't work with non-seekable formats, e.g.
'FLAC'.seek()returns-1on error, leading toself.framesbeing-1.