Skip to content

Instantly share code, notes, and snippets.

@crides
Created June 16, 2022 09:28
Show Gist options
  • Save crides/1acf383d7ae36bc1ea02e90c2f735ae8 to your computer and use it in GitHub Desktop.
Save crides/1acf383d7ae36bc1ea02e90c2f735ae8 to your computer and use it in GitHub Desktop.
Decompress zstd into frames
use std::fs::File;
use std::io::{self, Read, Write, BufReader, Seek};
use zstd::Decoder;
fn main() {
let src = std::env::args().skip(1).next().unwrap();
let mut input = Some(File::open(src).unwrap());
let mut buf = Vec::with_capacity(100000000);
let mut prev = None;
for i in 0.. {
dbg!(i);
let mut decoder = if let Some(input) = input.take() {
Decoder::new(input).unwrap().single_frame()
} else {
let mut prev: BufReader<_> = prev.unwrap();
dbg!(prev.stream_position().unwrap());
Decoder::with_buffer(prev).unwrap().single_frame()
};
let mut output = File::create(format!("out{}", i)).unwrap();
match decoder.read_to_end(&mut buf) {
Ok(size) => {
dbg!(size);
output.write_all(&buf).unwrap();
}
Err(e) => {
dbg!(e);
break;
}
}
buf.clear();
prev = Some(decoder.finish());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment