Skip to content

Commit

Permalink
Replace new_zstd_compressed with a more flexible new_with_options
Browse files Browse the repository at this point in the history
  • Loading branch information
DCNick3 authored and jturner314 committed Sep 14, 2024
1 parent 6481f77 commit 1203121
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ zip = { version = "0.6.3", default-features = false, optional = true }
default = ["compressed_npz", "num-complex-0_4"]
npz = ["zip"]
compressed_npz = ["npz", "zip/deflate"]
compressed_npz_zstd = ["npz", "zip/zstd"]

[dev-dependencies]
memmap2 = "0.2"
Expand Down
15 changes: 7 additions & 8 deletions src/npz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ impl<W: Write + Seek> NpzWriter<W> {
}
}

// TODO: it makes sense to add support for bzip2 also
// this necessitates some more generic API, as having three functions is janky... =)

/// Creates a new `.npz` file with zstd compression. While it is not directly supported by numpy,
/// it still could be useful (also it is possible to monkey-patch numpy to support it).
#[cfg(feature = "compressed_npz_zstd")]
pub fn new_zstd_compressed(writer: W, level: Option<i32>) -> NpzWriter<W> {
/// Creates a new `.npz` file with the specified options.
///
/// This allows you to use a custom compression method, such as [`CompressionMethod::Zstd`] or set other options.
///
/// Make sure to enable the `zstd` feature of the `zip` crate to use [`CompressionMethod::Zstd`] or other relevant features.
pub fn new_with_options(writer: W, options: FileOptions) -> NpzWriter<W> {
NpzWriter {
zip: ZipWriter::new(writer),
options: FileOptions::default().compression_method(CompressionMethod::ZSTD).compression_level(level),
options,
}
}

Expand Down

0 comments on commit 1203121

Please sign in to comment.