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

Method decompress_inner

crates/stdlib/src/zlib.rs:245–292  ·  view source on GitHub ↗
(
            inner: &mut PyDecompressInner,
            data: &[u8],
            bufsize: usize,
            max_length: Option<usize>,
            is_flush: bool,
            vm: &VirtualMachine,
  

Source from the content-addressed store, hash-verified

243 }
244
245 fn decompress_inner(
246 inner: &mut PyDecompressInner,
247 data: &[u8],
248 bufsize: usize,
249 max_length: Option<usize>,
250 is_flush: bool,
251 vm: &VirtualMachine,
252 ) -> PyResult<(PyResult<Vec<u8>>, bool)> {
253 let Some(d) = &mut inner.decompress else {
254 return Err(new_zlib_error(USE_AFTER_FINISH_ERR, vm));
255 };
256
257 let prev_in = d.total_in();
258 let res = if is_flush {
259 // if is_flush: ignore zdict, finish if final chunk
260 let calc_flush = |final_chunk| {
261 if final_chunk {
262 FlushDecompress::Finish
263 } else {
264 FlushDecompress::None
265 }
266 };
267 _decompress(data, &mut d.decompress, bufsize, max_length, calc_flush)
268 } else {
269 _decompress(data, d, bufsize, max_length, flush_sync)
270 }
271 .map_err(|e| new_zlib_error(e.to_string(), vm));
272 let (ret, stream_end) = match res {
273 Ok((buf, stream_end)) => (Ok(buf), stream_end),
274 Err(err) => (Err(err), false),
275 };
276 let consumed = (d.total_in() - prev_in) as usize;
277
278 // save unused input
279 let unconsumed = &data[consumed..];
280 if !unconsumed.is_empty() {
281 if stream_end {
282 let unused = [inner.unused_data.as_bytes(), unconsumed].concat();
283 inner.unused_data = vm.ctx.new_pyref(unused);
284 } else {
285 inner.unconsumed_tail = vm.ctx.new_bytes(unconsumed.to_vec());
286 }
287 } else if !inner.unconsumed_tail.is_empty() {
288 inner.unconsumed_tail = vm.ctx.empty_bytes.clone();
289 }
290
291 Ok((ret, stream_end))
292 }
293
294 #[pymethod]
295 fn decompress(&self, args: DecompressArgs, vm: &VirtualMachine) -> PyResult<Vec<u8>> {

Callers

nothing calls this directly

Calls 12

new_zlib_errorFunction · 0.85
_decompressFunction · 0.85
to_stringMethod · 0.80
new_pyrefMethod · 0.80
to_vecMethod · 0.80
ErrClass · 0.50
total_inMethod · 0.45
is_emptyMethod · 0.45
concatMethod · 0.45
as_bytesMethod · 0.45
new_bytesMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected