refactor: move the new ZipStreamReader API to the unstable module

This commit is contained in:
Marli Frost 2023-02-01 17:53:39 +00:00
parent 1eb491e96e
commit d06d4b295f
5 changed files with 21 additions and 8 deletions

View file

@ -42,3 +42,14 @@ mod spec;
mod types;
pub mod write;
mod zipcrypto;
/// Unstable APIs
///
/// All APIs accessible by importing this module are unstable; They may be changed in patch releases.
/// You MUST you an exact version specifier in `Cargo.toml`, to indicate the version of this API you're using:
///
/// ```toml
/// [dependencies]
/// zip = "=0.6.4"
/// ```
pub mod unstable;

View file

@ -30,7 +30,7 @@ use bzip2::read::BzDecoder;
use zstd::stream::read::Decoder as ZstdDecoder;
/// Provides high level API for reading from a stream.
pub mod stream;
pub(crate) mod stream;
// Put the struct declaration in a private module to convince rustdoc to display ZipArchive nicely
pub(crate) mod zip_archive {
@ -1014,8 +1014,6 @@ impl<'a> Drop for ZipFile<'a> {
}
}
/// **It is recommended to use [`stream`] for its highlevel API instead.**
///
/// Read ZipFile structures from a non-seekable reader.
///
/// This is an alternative method to read a zip file. If possible, use the ZipArchive functions

View file

@ -58,8 +58,8 @@ impl<R: Read> ZipStreamReader<R> {
/// Extraction is not atomic; If an error is encountered, some of the files
/// may be left on disk.
pub fn extract<P: AsRef<Path>>(self, directory: P) -> ZipResult<()> {
struct Extracter<'a>(&'a Path);
impl ZipStreamVisitor for Extracter<'_> {
struct Extractor<'a>(&'a Path);
impl ZipStreamVisitor for Extractor<'_> {
fn visit_file(&mut self, file: &mut ZipFile<'_>) -> ZipResult<()> {
let filepath = file
.enclosed_name()
@ -103,7 +103,7 @@ impl<R: Read> ZipStreamReader<R> {
}
}
self.visit(&mut Extracter(directory.as_ref()))
self.visit(&mut Extractor(directory.as_ref()))
}
}

View file

@ -380,7 +380,7 @@ impl ZipFileData {
})
}
pub fn enclosed_name(&self) -> Option<&path::Path> {
pub(crate) fn enclosed_name(&self) -> Option<&path::Path> {
if self.file_name.contains('\0') {
return None;
}
@ -398,7 +398,7 @@ impl ZipFileData {
}
/// Get unix mode for the file
pub fn unix_mode(&self) -> Option<u32> {
pub(crate) fn unix_mode(&self) -> Option<u32> {
if self.external_attributes == 0 {
return None;
}

4
src/unstable.rs Normal file
View file

@ -0,0 +1,4 @@
/// Provides high level API for reading from a stream.
pub mod stream {
pub use crate::read::stream::*;
}