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

Function compress

crates/stdlib/src/zlib.rs:93–106  ·  view source on GitHub ↗
(args: PyFuncCompressArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

91 /// Returns a bytes object containing compressed data.
92 #[pyfunction]
93 fn compress(args: PyFuncCompressArgs, vm: &VirtualMachine) -> PyResult<PyBytesRef> {
94 let PyFuncCompressArgs {
95 data,
96 level,
97 ref wbits,
98 } = args;
99 let level = level.ok_or_else(|| new_zlib_error("Bad compression level", vm))?;
100
101 let compress = InitOptions::new(wbits.value, vm)?.compress(level);
102 let mut encoder = ZlibEncoder::new_with_compress(Vec::new(), compress);
103 data.with_ref(|input_bytes| encoder.write_all(input_bytes).unwrap());
104 let encoded_bytes = encoder.finish().unwrap();
105 Ok(vm.ctx.new_bytes(encoded_bytes))
106 }
107
108 enum InitOptions {
109 Standard {

Callers

nothing calls this directly

Calls 8

new_zlib_errorFunction · 0.85
newFunction · 0.85
ok_or_elseMethod · 0.80
with_refMethod · 0.80
compressMethod · 0.45
unwrapMethod · 0.45
finishMethod · 0.45
new_bytesMethod · 0.45

Tested by

no test coverage detected