Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward seekable compressed streams #126

Open
maxnoe opened this issue Feb 6, 2021 · 1 comment
Open

Forward seekable compressed streams #126

maxnoe opened this issue Feb 6, 2021 · 1 comment

Comments

@maxnoe
Copy link

maxnoe commented Feb 6, 2021

Using boost::iostreams::filtering_istream together with one of the decompression filters, e.g. boost::iostreams::gzip_decompressor results in tellg returning -1 and setting the bad bid and seekg not working.

However, at least forward seeking and telling the number read bytes would be possible and would make working with these streams much easier for certain use cases (e.g. reading custom binary files compressed with these methods).

i.e. this:


#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file.hpp>


namespace io = boost::iostreams;
int main() {
    io::filtering_istream stream;
    stream.push(io::gzip_decompressor());
    stream.push(io::file_source("test.gzip"));
    
    std::cout << stream.tellg() << std::endl; // should print 0, prints -1
    stream.seekg(1000); // skip 1000 bytes
    std::cout << stream.tellg() << std::endl; // should print 1000, prints -1
    
    return 0;
}

See for example gzseek: https://refspecs.linuxbase.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/zlib-gzseek-1.html

and gztell: https://refspecs.linuxbase.org/LSB_3.0.0/LSB-Core-generic/LSB-Core-generic/zlib-gztell-1.html

@rdoeffinger
Copy link
Contributor

Not sure what happens for tellg, but I am not sure if the seekg behaviour is not the best possible.
Because for cases where seeking is not strictly possible since it will always involve reading all data, it might make sense to require use of stream.ignore(). That is assuming stream.ignore() is working, I have not tested it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants