Giter Site home page Giter Site logo

Optional compression about flate2-rs HOT 4 CLOSED

rust-lang avatar rust-lang commented on May 18, 2024
Optional compression

from flate2-rs.

Comments (4)

alexcrichton avatar alexcrichton commented on May 18, 2024

Hm it does seem that zlib has some... interesting behavior with gz files. I've historically also seen how they support concatenated gzip streams being interpreted as one stream as well. I personally prefer to be more explicit about what's going on rather than hide that under the covers...

Along those lines, it looks like zlib mainly only supports this sort of operation with a file descriptor as a file as the backing storage? Along those lines couldn't this be done by using seek to go back to the beginning of a file in the case that the header wasn't parsed? You shouldn't need to relinquish ownership as you can hand in &mut R instead of just R.

It may also be prudent though to add the ability to get back out the initial stream when trying to parse a gz header

from flate2-rs.

mishun avatar mishun commented on May 18, 2024

Seek will work for files, although it is even uglier because something simple with seek instead of reopen, like:

    let mut reader = io::BufReader::new(try!(fs::File::open(path)));
    match GzDecoder::new(&mut reader) {
        Ok(gz) => { parse(gz) }

        Err(ref e) if e.kind() == io::ErrorKind::InvalidInput => {
            try!(reader.seek(SeekFrom::Start(0)));
            parse(reader)
        }

        Err(e) => { Err(e) }
    }

will not pass borrow check.

Also, it would be nice to be able to read in such way from pipes or stdin (like minisat do with zlib)

from flate2-rs.

alexcrichton avatar alexcrichton commented on May 18, 2024

Yeah you won't be able to seek on pipes but you can perhaps use some buffering to try to decode just the header of the stream to see if it's a gzip stream or not (the first two bytes should tell I believe).

You don't need to an an explicit layer of buffering yourself (as this library already does so), and this should also work fine with pipes as it just requires R: Read

from flate2-rs.

alexcrichton avatar alexcrichton commented on May 18, 2024

Ok I'm going to close this for now as I'd prefer the types in this library do what they say on the tin, and otherwise I think all the bits and pieces are there now to recover this if need be.

from flate2-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.