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

Method flush

crates/stdlib/src/compression.rs:248–272  ·  view source on GitHub ↗
(&mut self, mode: C::Flush, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

246 }
247
248 pub fn flush(&mut self, mode: C::Flush, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
249 let mut buf = Vec::new();
250 let compressor = self.get_compressor(vm)?;
251
252 let status = loop {
253 if buf.len() == buf.capacity() {
254 buf.reserve(C::DEF_BUF_SIZE);
255 }
256 let status = compressor.compress_vec(&[], &mut buf, mode, vm)?;
257 if buf.len() != buf.capacity() {
258 break status;
259 }
260 };
261
262 if status.to_usize() == C::Status::EOF.to_usize() {
263 if mode.to_usize() == C::Flush::FINISH.to_usize() {
264 self.compressor = None;
265 } else {
266 return Err(C::new_error("unexpected eof", vm));
267 }
268 }
269
270 buf.shrink_to_fit();
271 Ok(buf)
272 }
273}
274
275#[derive(Debug)]

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
get_compressorMethod · 0.80
shrink_to_fitMethod · 0.80
ErrClass · 0.50
lenMethod · 0.45
capacityMethod · 0.45
reserveMethod · 0.45
compress_vecMethod · 0.45
to_usizeMethod · 0.45

Tested by

no test coverage detected