dbry / WavPack

WavPack encode/decode library, command-line programs, and several plugins
BSD 3-Clause "New" or "Revised" License
371 stars 67 forks source link

reader push_back_byte question #152

Closed sezero closed 1 year ago

sezero commented 1 year ago

Does wavpack ever use push_back_byte by modifying the stdio buffer? I.e.: Can I safely use fseek(file, -1, SEEK_CUR) for that reader functionality? I'll have to use reader functions without stdio at all, e.g. a reader from const memory, a file api without any ungetc functionality at all, etc.

My limited scanning of library shows that the actual intent is simply going back one byte after successfully reading one byte and without modifying the buffer (in WavpackOpenFileInputEx64()), but I just have to ask...

sezero commented 1 year ago

PING @dbry ?

dbry commented 1 year ago

Hi @sezero . Sorry for the delayed response; was out of town then had house guest.

Yes, you can always use seek (-1). The reason I did not simply use the relative seek callback is that the decoder will work quite well without general seek functionality, for example when reading from a pipe. Of course, this precludes actual seeking to a specific sample index or getting tags at EOF, but is useful otherwise.

But I did need the ability to push back a single byte to avoid a lot of ugliness. The byte pushed back will always be the same as the one read, and at most only one byte will be pushed back, so it's pretty trivial to implement. I think that even pipes are guaranteed to provide at least this functionality.

sezero commented 1 year ago

OK, thank you.

Closing the ticket.