From 3efa590ddf73eec548da867fe269a8b77ac10f2f Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Sat, 14 Sep 2024 01:31:57 -0400 Subject: [PATCH] Update zip dependency to version 2 (#78) --- Cargo.toml | 2 +- src/npz.rs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d3a8ca2..39189f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/npz.rs b/src/npz.rs index ba488db..19fdaed 100644 --- a/src/npz.rs +++ b/src/npz.rs @@ -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. @@ -78,7 +78,7 @@ impl From for WriteNpzError { /// ``` pub struct NpzWriter { zip: ZipWriter, - options: FileOptions, + options: SimpleFileOptions, } impl NpzWriter { @@ -88,7 +88,7 @@ impl NpzWriter { pub fn new(writer: W) -> NpzWriter { NpzWriter { zip: ZipWriter::new(writer), - options: FileOptions::default().compression_method(CompressionMethod::Stored), + options: SimpleFileOptions::default().compression_method(CompressionMethod::Stored), } } @@ -99,16 +99,18 @@ impl NpzWriter { pub fn new_compressed(writer: W) -> NpzWriter { 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 { + /// 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 { NpzWriter { zip: ZipWriter::new(writer), options, @@ -152,7 +154,7 @@ impl NpzWriter { /// [`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 { + pub fn finish(self) -> Result { let mut writer = self.zip.finish()?; writer.flush().map_err(ZipError::from)?; Ok(writer)