Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into noseek_write
Browse files Browse the repository at this point in the history
  • Loading branch information
Plecra committed Nov 15, 2020
2 parents b0742d9 + 4d8a068 commit c0882ad
Show file tree
Hide file tree
Showing 16 changed files with 529 additions and 190 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]

name = "zip"
version = "0.5.6"
version = "0.5.8"
authors = ["Mathijs van de Nes <[email protected]>"]
license = "MIT"
repository = "https://github.com/mvdnes/zip-rs.git"
Expand All @@ -13,7 +12,8 @@ Library to support the reading and writing of zip files.
edition = "2018"

[dependencies]
flate2 = { version = "1.0", default-features = false, optional = true }
# FIXME(#170): flate2 1.0.15 has an MSRV of 1.36.0, breaking ours. We'll update when we know if this will be addressed
flate2 = { version = ">=1.0.0, <=1.0.14", default-features = false, optional = true }
time = { version = "0.1", optional = true }
byteorder = "1.3"
bzip2 = { version = "0.3", optional = true }
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
zip-rs
======

[![Build Status](https://travis-ci.org/mvdnes/zip-rs.svg?branch=master)](https://travis-ci.org/mvdnes/zip-rs)
[![Build status](https://ci.appveyor.com/api/projects/status/gsnpqcodg19iu253/branch/master?svg=true)](https://ci.appveyor.com/project/mvdnes/zip-rs/branch/master)
[![Build Status](https://img.shields.io/github/workflow/status/zip-rs/zip/CI)](https://github.com/zip-rs/zip/actions?query=branch%3Amaster+workflow%3ACI)
[![Crates.io version](https://img.shields.io/crates/v/zip.svg)](https://crates.io/crates/zip)

[Documentation](http://mvdnes.github.io/rust-docs/zip-rs/zip/index.html)
Expand Down
13 changes: 6 additions & 7 deletions examples/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ fn real_main() -> i32 {

for i in 0..archive.len() {
let mut file = archive.by_index(i).unwrap();
let outpath = file.sanitized_name();
let outpath = match file.enclosed_name() {
Some(path) => path.to_owned(),
None => continue,
};

{
let comment = file.comment();
Expand All @@ -28,17 +31,13 @@ fn real_main() -> i32 {
}

if (&*file.name()).ends_with('/') {
println!(
"File {} extracted to \"{}\"",
i,
outpath.as_path().display()
);
println!("File {} extracted to \"{}\"", i, outpath.display());
fs::create_dir_all(&outpath).unwrap();
} else {
println!(
"File {} extracted to \"{}\" ({} bytes)",
i,
outpath.as_path().display(),
outpath.display(),
file.size()
);
if let Some(p) = outpath.parent() {
Expand Down
12 changes: 9 additions & 3 deletions examples/file_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ fn real_main() -> i32 {

for i in 0..archive.len() {
let file = archive.by_index(i).unwrap();
let outpath = file.sanitized_name();
let outpath = match file.enclosed_name() {
Some(path) => path,
None => {
println!("Entry {} has a suspicious path", file.name());
continue;
}
};

{
let comment = file.comment();
Expand All @@ -32,13 +38,13 @@ fn real_main() -> i32 {
println!(
"Entry {} is a directory with name \"{}\"",
i,
outpath.as_path().display()
outpath.display()
);
} else {
println!(
"Entry {} is a file with name \"{}\" ({} bytes)",
i,
outpath.as_path().display(),
outpath.display(),
file.size()
);
}
Expand Down
2 changes: 2 additions & 0 deletions examples/write_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ where
// Some unzip tools unzip files with directory paths correctly, some do not!
if path.is_file() {
println!("adding file {:?} as {:?} ...", path, name);
#[allow(deprecated)]
zip.start_file_from_path(name, options)?;
let mut f = File::open(path)?;

Expand All @@ -90,6 +91,7 @@ where
// Only if not root! Avoids path spec / warning
// and mapname conversion failed error on unzip
println!("adding dir {:?} as {:?} ...", path, name);
#[allow(deprecated)]
zip.add_directory_from_path(name, options)?;
}
}
Expand Down
65 changes: 53 additions & 12 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,75 @@
use std::fmt;

#[allow(deprecated)]
/// Compression methods for the contents of a ZIP file.
#[derive(Copy, Clone, PartialEq, Debug)]
/// Identifies the storage format used to compress a file within a ZIP archive.
///
/// Each file's compression method is stored alongside it, allowing the
/// contents to be read without context.
///
/// When creating ZIP files, you may choose the method to use with
/// [`zip::write::FileOptions::compression_method`]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum CompressionMethod {
/// The file is stored (no compression)
/// Store the file as is
Stored,
/// Deflate using any flate2 backend
/// Compress the file using Deflate
#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib"
))]
Deflated,
/// File is compressed using BZIP2 algorithm
/// Compress the file using BZIP2
#[cfg(feature = "bzip2")]
Bzip2,
/// Unsupported compression method
#[deprecated(
since = "0.5.7",
note = "implementation details are being removed from the public API"
)]
#[deprecated(since = "0.5.7", note = "use the constants instead")]
Unsupported(u16),
}

#[allow(deprecated, missing_docs)]
/// All compression methods defined for the ZIP format
impl CompressionMethod {
pub const STORE: Self = CompressionMethod::Stored;
pub const SHRINK: Self = CompressionMethod::Unsupported(1);
pub const REDUCE_1: Self = CompressionMethod::Unsupported(2);
pub const REDUCE_2: Self = CompressionMethod::Unsupported(3);
pub const REDUCE_3: Self = CompressionMethod::Unsupported(4);
pub const REDUCE_4: Self = CompressionMethod::Unsupported(5);
pub const IMPLODE: Self = CompressionMethod::Unsupported(6);
#[cfg(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib"
))]
pub const DEFLATE: Self = CompressionMethod::Deflated;
#[cfg(not(any(
feature = "deflate",
feature = "deflate-miniz",
feature = "deflate-zlib"
)))]
pub const DEFLATE: Self = CompressionMethod::Unsupported(8);
pub const DEFLATE64: Self = CompressionMethod::Unsupported(9);
pub const PKWARE_IMPLODE: Self = CompressionMethod::Unsupported(10);
#[cfg(feature = "bzip2")]
pub const BZIP2: Self = CompressionMethod::Bzip2;
#[cfg(not(feature = "bzip2"))]
pub const BZIP2: Self = CompressionMethod::Unsupported(12);
pub const LZMA: Self = CompressionMethod::Unsupported(14);
pub const IBM_ZOS_CMPSC: Self = CompressionMethod::Unsupported(16);
pub const IBM_TERSE: Self = CompressionMethod::Unsupported(18);
pub const ZSTD_DEPRECATED: Self = CompressionMethod::Unsupported(20);
pub const ZSTD: Self = CompressionMethod::Unsupported(93);
pub const MP3: Self = CompressionMethod::Unsupported(94);
pub const XZ: Self = CompressionMethod::Unsupported(95);
pub const JPEG: Self = CompressionMethod::Unsupported(96);
pub const WAVPACK: Self = CompressionMethod::Unsupported(97);
pub const PPMD: Self = CompressionMethod::Unsupported(98);
}
impl CompressionMethod {
/// Converts an u16 to its corresponding CompressionMethod
#[deprecated(
since = "0.5.7",
note = "implementation details are being removed from the public API"
note = "use a constant to construct a compression method"
)]
pub fn from_u16(val: u16) -> CompressionMethod {
#[allow(deprecated)]
Expand All @@ -52,7 +93,7 @@ impl CompressionMethod {
/// Converts a CompressionMethod to a u16
#[deprecated(
since = "0.5.7",
note = "implementation details are being removed from the public API"
note = "to match on other compression methods, use a constant"
)]
pub fn to_u16(self) -> u16 {
#[allow(deprecated)]
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! A basic ZipReader/Writer crate
//! An ergonomic API for reading and writing ZIP files.
//!
//! The current implementation is based on [PKWARE's APPNOTE.TXT v6.3.9](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT)
// TODO(#184): Decide on the crate's bias: Do we prioritise permissiveness/correctness/speed/ergonomics?

#![warn(missing_docs)]

Expand Down
Loading

0 comments on commit c0882ad

Please sign in to comment.