Skip to content

Commit

Permalink
Add zstd-compressed archives support
Browse files Browse the repository at this point in the history
  • Loading branch information
DCNick3 authored and jturner314 committed Sep 14, 2024
1 parent 08bef59 commit 6481f77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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
13 changes: 13 additions & 0 deletions src/npz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ 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> {
NpzWriter {
zip: ZipWriter::new(writer),
options: FileOptions::default().compression_method(CompressionMethod::ZSTD).compression_level(level),
}
}

/// Adds an array with the specified `name` to the `.npz` file.
///
/// Note that a `.npy` extension will be appended to `name`; this matches NumPy's behavior.
Expand Down

0 comments on commit 6481f77

Please sign in to comment.