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

Method compress

crates/stdlib/src/bz2.rs:162–174  ·  view source on GitHub ↗
(&self, data: ArgBytesLike, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

160 impl BZ2Compressor {
161 #[pymethod]
162 fn compress(&self, data: ArgBytesLike, vm: &VirtualMachine) -> PyResult<PyBytesRef> {
163 let mut state = self.state.lock();
164 if state.flushed {
165 return Err(vm.new_value_error("Compressor has been flushed"));
166 }
167
168 // let CompressorState { flushed, encoder } = &mut *state;
169 let CompressorState { encoder, .. } = &mut *state;
170
171 // TODO: handle Err
172 data.with_ref(|input_bytes| encoder.as_mut().unwrap().write_all(input_bytes).unwrap());
173 Ok(vm.ctx.new_bytes(Vec::new()))
174 }
175
176 #[pymethod]
177 fn flush(&self, vm: &VirtualMachine) -> PyResult<PyBytesRef> {

Callers 5

compressFunction · 0.95
testCompressMethod · 0.95
testCompressChunks10Method · 0.95
testCompress4GMethod · 0.95

Calls 7

newFunction · 0.85
with_refMethod · 0.80
ErrClass · 0.50
lockMethod · 0.45
unwrapMethod · 0.45
as_mutMethod · 0.45
new_bytesMethod · 0.45

Tested by 4

testCompressMethod · 0.76
testCompressChunks10Method · 0.76
testCompress4GMethod · 0.76