Function pack_file

Source
pub fn pack_file(src_path: &str, dst_path: &str, enc: Encoder) -> Result<()>
Expand description

Compresses the contents in “src_path” using compression algorithms and saves it to “dst_path”. Note that even if “dst_path” already exists, it truncates (overwrites).

Make sure to use stream – reading the entire file at once may cause OOM!

let d = fs::read(src_path)?; let compressed = zstd::stream::encode_all(Cursor::new(&d[..]), lvl)?;

let d = fs::read(src_path)?; let decoded = zstd::stream::decode_all(Cursor::new(&d[..]))?;

let mut dec = zstd::Decoder::new(BufReader::new(f1))?; let mut decoded = Vec::new(); dec.read_to_end(&mut decoded)?; f2.write_all(&decoded[..])?;