| 175 | |
| 176 | #[pymethod] |
| 177 | fn flush(&self, vm: &VirtualMachine) -> PyResult<PyBytesRef> { |
| 178 | let mut state = self.state.lock(); |
| 179 | if state.flushed { |
| 180 | return Err(vm.new_value_error("Repeated call to flush()")); |
| 181 | } |
| 182 | |
| 183 | // let CompressorState { flushed, encoder } = &mut *state; |
| 184 | let CompressorState { encoder, .. } = &mut *state; |
| 185 | |
| 186 | // TODO: handle Err |
| 187 | let out = encoder.take().unwrap().finish().unwrap(); |
| 188 | state.flushed = true; |
| 189 | Ok(vm.ctx.new_bytes(out.to_vec())) |
| 190 | } |
| 191 | |
| 192 | #[pymethod(name = "__reduce__")] |
| 193 | fn reduce(&self, vm: &VirtualMachine) -> PyResult<()> { |