Comments (4)
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.
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.
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.
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)
- Feature request: `set_dictionary` in pure Rust backend HOT 2
- Cannot compile when `default-features` are disabled (`false`) HOT 1
- can't find crate for `flate2`
- support 'deflate64'? HOT 6
- `GzDecoder` eager reading in the constructor blocks IO HOT 9
- Error on compiling flate2 on rust 1.57.0 HOT 2
- flate2::bufread::GzDecoder doesn't impl BufRead? HOT 3
- unsafe review: Potential (not actual) dangling pointers after inflate/deflate HOT 2
- total_in(&self) / total_out(&self) implementation for GzDecoder / GzEncoder / MultiGzDecoder HOT 2
- Issues with newly created file in read-write mode HOT 7
- Implement BufRead/Write for en/decoders alongside Read/Write
- rapidgzip
- Zlib succes while miniz_oxide fails HOT 5
- Testing validity of the data without the actual decompression
- Tree borrows violation occurs when using zlib backend HOT 5
- Some compressed files can only read a portion of the lines using GzDecoder. HOT 3
- question: Slowdown after upgrading from 1.0.26 to 1.0.28 HOT 7
- Using MultiGzDecoder for file with garbage after gzip data HOT 3
- Decoding a zip file returns the Error "corrupt deflate stream" HOT 2
- why GzDecoder can't read stream correct HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flate2-rs.