Open jtmoon79 opened 6 months ago
Can you retry using std::io::copy
like in the examples instead of a single read call?
https://docs.rs/lz4_flex/latest/lz4_flex/#example-decompress-data-on-stdin-with-frame-format
Thanks @PSeitz . I got this working. I was not setting the length of the passed buffer (see https://github.com/rust-lang/rust/issues/96915).
This code works (notice the call to resize
)
use std::fs::File;
use std::fs::OpenOptions;
use std::io::prelude::Read;
use std::io::BufReader;
use std::path::Path;
use ::lz4_flex;
fn main() {
let mut open_options = OpenOptions::new();
let path = String::from("/tmp/file.lz4");
let path_std = Path::new(&path);
let file_lz: File = match open_options.read(true).open(path_std) {
Ok(val) => val,
Err(err) => panic!("{}", err),
};
let bufreader = BufReader::<File>::new(file_lz);
let mut lz4_decoder = lz4_flex::frame::FrameDecoder::new(bufreader);
let mut buffer = Vec::<u8>::with_capacity(1024);
buffer.resize(1024, 0);
let sz = match lz4_decoder.read(&mut buffer) {
Ok(sz) => sz,
Err(err) => panic!("{}", err),
};
eprintln!("buffer: {:?}", &buffer[..sz]);
}
If you're interested, I can submit a PR for this at /examples/decompress_file.rs
.
Yeah a PR would be nice, e.g. /examples/decompress_file_into_vec.rs
I'm trying to use
lz4_flex
to decompress a small.lz4
file. The file was compressed usinglz4c
on Ubuntu 22.However, my various attempts at reading the file
file.lz4
using alz4_flex::frame::FrameDecoder
and calls to.read
or.read_exact
do returnOk
. However they do not appear to write anything to the passedVec<u8>
.My code is
Could you provide an example for decompressing an
.lz4
file? Reviewing the examples, it was not obvious to me how to go about this as the examples only use "live" stdin streaming.