MCPcopy Index your code
hub / github.com/RustPython/RustPython / compress

Method compress

crates/stdlib/src/compression.rs:230–246  ·  view source on GitHub ↗
(&mut self, data: &[u8], vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

228 }
229
230 pub fn compress(&mut self, data: &[u8], vm: &VirtualMachine) -> PyResult<Vec<u8>> {
231 let mut buf = Vec::new();
232 let compressor = self.get_compressor(vm)?;
233
234 for mut chunk in data.chunks(C::CHUNKSIZE) {
235 while !chunk.is_empty() {
236 buf.reserve(C::DEF_BUF_SIZE);
237 let prev_in = compressor.total_in();
238 compressor.compress_vec(chunk, &mut buf, C::Flush::NONE, vm)?;
239 let consumed = compressor.total_in() - prev_in;
240 chunk = &chunk[consumed..];
241 }
242 }
243
244 buf.shrink_to_fit();
245 Ok(buf)
246 }
247
248 pub fn flush(&mut self, mode: C::Flush, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
249 let mut buf = Vec::new();

Callers 2

stdlib_zlib.pyFile · 0.45

Calls 8

newFunction · 0.85
get_compressorMethod · 0.80
shrink_to_fitMethod · 0.80
chunksMethod · 0.45
is_emptyMethod · 0.45
reserveMethod · 0.45
total_inMethod · 0.45
compress_vecMethod · 0.45

Tested by

no test coverage detected