Skip to content

Commit

Permalink
Fixup: raise error and docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
milesgranger committed Sep 5, 2021
1 parent 5dc6973 commit a75c5fe
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/brotli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ impl Compressor {
/// Consume the current compressor state and return the compressed stream
/// **NB** The compressor will not be usable after this method is called.
pub fn finish(&mut self) -> PyResult<RustyBuffer> {
// presently, pyo3 won't accept consuming an object, ie `finish(self)`
// so instead we're going to swap out whatever `inner` is, to allow
// consuming it.
let mut inner = None;
std::mem::swap(&mut inner, &mut self.inner);

Expand Down
3 changes: 0 additions & 3 deletions src/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ impl Compressor {
/// Consume the current compressor state and return the compressed stream
/// **NB** The compressor will not be usable after this method is called.
pub fn finish(&mut self) -> PyResult<RustyBuffer> {
// presently, pyo3 won't accept consuming an object, ie `finish(self)`
// so instead we're going to swap out whatever `inner` is, to allow
// consuming it.
let mut inner = None;
std::mem::swap(&mut inner, &mut self.inner);

Expand Down
3 changes: 0 additions & 3 deletions src/gzip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ impl Compressor {
/// Consume the current compressor state and return the compressed stream
/// **NB** The compressor will not be usable after this method is called.
pub fn finish(&mut self) -> PyResult<RustyBuffer> {
// presently, pyo3 won't accept consuming an object, ie `finish(self)`
// so instead we're going to swap out whatever `inner` is, to allow
// consuming it.
let mut inner = None;
std::mem::swap(&mut inner, &mut self.inner);

Expand Down
4 changes: 2 additions & 2 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::fs::{File, OpenOptions};
use std::io::{copy, Cursor, Read, Seek, SeekFrom, Write};

use crate::exceptions::{CompressionError, DecompressionError};
use crate::exceptions::CompressionError;
use crate::BytesType;
use numpy::PyArray1;
use pyo3::class::buffer::PyBufferProtocol;
Expand Down Expand Up @@ -606,7 +606,7 @@ pub(crate) fn stream_compress<W: Write>(inner: &mut Option<W>, input: &[u8]) ->
let result = std::io::copy(&mut Cursor::new(input), inner).map(|v| v as usize);
crate::to_py_err!(CompressionError -> result)
}
None => Err(DecompressionError::new_err(
None => Err(CompressionError::new_err(
"Compressor looks to have been consumed via `finish()`. \
please create a new compressor instance.",
)),
Expand Down
3 changes: 0 additions & 3 deletions src/lz4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ impl Compressor {
/// Consume the current compressor state and return the compressed stream
/// **NB** The compressor will not be usable after this method is called.
pub fn finish(&mut self) -> PyResult<RustyBuffer> {
// presently, pyo3 won't accept consuming an object, ie `finish(self)`
// so instead we're going to swap out whatever `inner` is, to allow
// consuming it.
let mut inner = None;
std::mem::swap(&mut inner, &mut self.inner);

Expand Down
3 changes: 0 additions & 3 deletions src/snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@ impl Compressor {
/// Consume the current compressor state and return the compressed stream
/// **NB** The compressor will not be usable after this method is called.
pub fn finish(&mut self) -> PyResult<RustyBuffer> {
// presently, pyo3 won't accept consuming an object, ie `finish(self)`
// so instead we're going to swap out whatever `inner` is, to allow
// consuming it.
let mut inner = None;
std::mem::swap(&mut inner, &mut self.inner);

Expand Down
3 changes: 0 additions & 3 deletions src/zstd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ impl Compressor {
/// Consume the current compressor state and return the compressed stream
/// **NB** The compressor will not be usable after this method is called.
pub fn finish(&mut self) -> PyResult<RustyBuffer> {
// presently, pyo3 won't accept consuming an object, ie `finish(self)`
// so instead we're going to swap out whatever `inner` is, to allow
// consuming it.
let mut inner = None;
std::mem::swap(&mut inner, &mut self.inner);

Expand Down
4 changes: 4 additions & 0 deletions tests/test_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,7 @@ def test_streams_compressor(mod):
# just empty bytes after the first .finish()
# same behavior as brotli.Compressor()
assert bytes(compressor.finish()) == b""

# compress will raise an error as the stream is completed
with pytest.raises(cramjam.CompressionError):
compressor.compress(b'data')

0 comments on commit a75c5fe

Please sign in to comment.