Skip to content

Commit

Permalink
Support independent mode in LZ4 compressor (#125)
Browse files Browse the repository at this point in the history
* Support independent mode in LZ4 compressor

* Allow disabling checksum in LZ4 compressor
  • Loading branch information
ods authored Jan 15, 2024
1 parent 760cdce commit 505f3f7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cramjam-python/src/lz4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::exceptions::{CompressionError, DecompressionError};
use crate::io::{AsBytes, RustyBuffer};
use crate::BytesType;
use libcramjam::lz4::lz4::{BlockMode, ContentChecksum};
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
use pyo3::PyResult;
Expand Down Expand Up @@ -210,10 +211,18 @@ pub struct Compressor {
impl Compressor {
/// Initialize a new `Compressor` instance.
#[new]
pub fn __init__(level: Option<u32>) -> PyResult<Self> {
pub fn __init__(level: Option<u32>, content_checksum: Option<bool>, block_linked: Option<bool>) -> PyResult<Self> {
let inner = libcramjam::lz4::lz4::EncoderBuilder::new()
.auto_flush(true)
.level(level.unwrap_or_else(|| DEFAULT_COMPRESSION_LEVEL))
.level(level.unwrap_or(DEFAULT_COMPRESSION_LEVEL))
.checksum(match content_checksum {
Some(false) => ContentChecksum::NoChecksum,
_ => ContentChecksum::ChecksumEnabled,
})
.block_mode(match block_linked {
Some(false) => BlockMode::Independent,
_ => BlockMode::Linked,
})
.build(Cursor::new(vec![]))?;
Ok(Self { inner: Some(inner) })
}
Expand Down

0 comments on commit 505f3f7

Please sign in to comment.