Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update zip dependency to version 2 #78

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ndarray = "0.16"
num-complex-0_4 = { package = "num-complex", version = "0.4", optional = true }
num-traits = "0.2"
py_literal = "0.4"
zip = { version = "0.6.3", default-features = false, optional = true }
zip = { version = "2", default-features = false, optional = true }

[features]
default = ["compressed_npz", "num-complex-0_4"]
Expand Down
18 changes: 10 additions & 8 deletions src/npz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::error::Error;
use std::fmt;
use std::io::{BufWriter, Read, Seek, Write};
use zip::result::ZipError;
use zip::write::FileOptions;
use zip::write::SimpleFileOptions;
use zip::{CompressionMethod, ZipArchive, ZipWriter};

/// An error writing a `.npz` file.
Expand Down Expand Up @@ -78,7 +78,7 @@ impl From<WriteNpyError> for WriteNpzError {
/// ```
pub struct NpzWriter<W: Write + Seek> {
zip: ZipWriter<W>,
options: FileOptions,
options: SimpleFileOptions,
}

impl<W: Write + Seek> NpzWriter<W> {
Expand All @@ -88,7 +88,7 @@ impl<W: Write + Seek> NpzWriter<W> {
pub fn new(writer: W) -> NpzWriter<W> {
NpzWriter {
zip: ZipWriter::new(writer),
options: FileOptions::default().compression_method(CompressionMethod::Stored),
options: SimpleFileOptions::default().compression_method(CompressionMethod::Stored),
}
}

Expand All @@ -99,16 +99,18 @@ impl<W: Write + Seek> NpzWriter<W> {
pub fn new_compressed(writer: W) -> NpzWriter<W> {
NpzWriter {
zip: ZipWriter::new(writer),
options: FileOptions::default().compression_method(CompressionMethod::Deflated),
options: SimpleFileOptions::default().compression_method(CompressionMethod::Deflated),
}
}

/// 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.
/// 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> {
/// Make sure to enable the relevant features of the `zip` crate to use
/// [`CompressionMethod::Zstd`] or other features.
pub fn new_with_options(writer: W, options: SimpleFileOptions) -> NpzWriter<W> {
NpzWriter {
zip: ZipWriter::new(writer),
options,
Expand Down Expand Up @@ -152,7 +154,7 @@ impl<W: Write + Seek> NpzWriter<W> {
/// [`BufWriter`](std::io::BufWriter)) flush the writer, any errors that
/// occur during drop will be silently ignored. So, it's necessary to call
/// `.finish()` to properly handle errors.
pub fn finish(mut self) -> Result<W, WriteNpzError> {
pub fn finish(self) -> Result<W, WriteNpzError> {
let mut writer = self.zip.finish()?;
writer.flush().map_err(ZipError::from)?;
Ok(writer)
Expand Down