-
Notifications
You must be signed in to change notification settings - Fork 27
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
support streaming read #10
Comments
This is a very interesting point! I was wondering whether there was a generic way of transforming an In the meantime, I think the easiest way to support streaming would be to extract the loop body of the I probably won't have time to look at it more closely this week, but feel free to send a PR if you want to give it a try! |
Thanks for the explanation! Regarding the I'm not sure I'll have time in the coming days as well though. Maybe I'll come to that later if/when I get rid of other libraries that bind to OS libraries, and will be otherwise on pure Rust. |
Hi, |
I've been working on an implementation for this ticket based off of the LzmaDec_TryDummy function in libhtp's port of the LZMA SDK. The main issue in incrementally executing the loop is that you may end up in a partially corrupted state if you are in the middle of a function and you fail to read the next byte because it isn't available yet. Also, I used the I'll publish this soon. It will most likely be dependant on #50 . |
I'm now wondering whether integrating with async/await would be the way to go to implement this. Something like taking futures::io::AsyncRead as input and writing to a futures::io::AsyncWrite or a futures::stream::Stream of bytes as output. I don't know what the performance overhead of that would be, but from a programming perspective the code should be similar to the current one (with some extra |
@gendx I published a PR for this if you want to have a look. I haven't really thought of implementing it using futures but that's an interesting idea. It would add a couple extra dependencies for those who want to use a streaming API and possibly require a runtime. I was looking for a solution that uses an |
It'd be useful if a |
Reading line by line is very important, for example, let f_in = std::fs::File::open("sample.txt.xz").unwrap();
let d = flate2::read::GzDecoder::new(f_in);
let mut buf_reader = std::io::BufReader::new(d);
for line in buf_reader.lines() {
println!("{}", line)
} |
Currently, a blocking function is provided by the library that reads from
io::BufRead
and writes toio::Write
. This enforces the user of the library to read all contents into memory, or into a file.Sometimes, however, it is only needed to traverse the data, but not have it all at once.
Such a thing could be achieved by having a function that, given
io::Read
, gives something that implementsio::Read
as well. This way, you can progressively read compressed or decompressed stream, while the library will internally read the underlying stream. This is howxz2
crate works, for example, see the function signature ofxz2::read::XzDecoder::new
. This also looks very flexible and intuitive as well: decompressor starts to act like a "pipe" (in unix terminology), rather than something that writes.Support of it in lzma-rs would be very nice I think.
Personally, I'm raising the issue because I wanted to try this library in rua https://github.com/vn971/rua Here I am using an intermediate layer of decompression for another function that accepts
Read
https://github.com/vn971/rua/blob/master/src/tar_check.rs#L26 (however, the underlying libraryxz2
is not pure Rust, but uses bindings)Thoughts?
The text was updated successfully, but these errors were encountered: