Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 7 additions & 8 deletions src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ use crate::types::{
use crate::write::SimpleFileOptions;
use crate::zipcrypto::{ZipCryptoReader, ZipCryptoReaderValid, ZipCryptoValidator};
use crate::ZIP64_BYTES_THR;
use core::mem::{replace, size_of};
use core::ops::{Deref, Range};
use indexmap::IndexMap;
use std::borrow::Cow;
use std::ffi::OsStr;
use std::fs::create_dir_all;
use std::io::{self, copy, prelude::*, sink, SeekFrom};
use std::mem;
use std::mem::size_of;
use std::ops::{Deref, Range};
use std::path::{Component, Path, PathBuf};
use std::sync::{Arc, OnceLock};

mod config;

pub use config::*;
pub use config::{Config, ArchiveOffset};

/// Provides high level API for reading from a stream.
pub(crate) mod stream;
Expand Down Expand Up @@ -313,7 +311,8 @@ impl<R: Read> Read for SeekableTake<'_, R> {
}

pub(crate) fn make_writable_dir_all<T: AsRef<Path>>(outpath: T) -> Result<(), ZipError> {
create_dir_all(outpath.as_ref())?;
use std::fs;
fs::create_dir_all(outpath.as_ref())?;
#[cfg(unix)]
{
// Dirs must be writable until all normal files are extracted
Expand Down Expand Up @@ -854,7 +853,7 @@ impl<R: Read + Seek> ZipArchive<R> {
) -> ZipResult<()> {
use std::fs;

create_dir_all(&directory)?;
fs::create_dir_all(&directory)?;
let directory = directory.as_ref().canonicalize()?;

let root_dir = root_dir_filter
Expand Down Expand Up @@ -1603,7 +1602,7 @@ impl<'a> ZipReadOptions<'a> {
/// Methods for retrieving information on zip files
impl<'a, R: Read> ZipFile<'a, R> {
pub(crate) fn take_raw_reader(&mut self) -> io::Result<io::Take<&'a mut R>> {
mem::replace(&mut self.reader, ZipFileReader::NoReader).into_inner()
replace(&mut self.reader, ZipFileReader::NoReader).into_inner()
}

/// Get the version of the file
Expand Down
5 changes: 2 additions & 3 deletions src/read/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use super::{
};
use crate::spec::FixedSizeBlock;
use indexmap::IndexMap;
use std::fs;
use std::fs::create_dir_all;
use std::io::{self, Read};
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -58,7 +56,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<()> {
create_dir_all(&directory)?;
use std::fs;
fs::create_dir_all(&directory)?;
let directory = directory.as_ref().canonicalize()?;
struct Extractor(PathBuf, IndexMap<Box<str>, ()>);
impl ZipStreamVisitor for Extractor {
Expand Down
22 changes: 11 additions & 11 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ use crate::types::{
ZipRawValues, MIN_VERSION,
};
use crate::write::ffi::S_IFLNK;
use core::default::Default;
use core::fmt::{Debug, Formatter};
use core::marker::PhantomData;
use core::mem;
#[cfg(feature = "deflate-zopfli")]
use core::num::NonZeroU64;
use core::str::{from_utf8, Utf8Error};
use crc32fast::Hasher;
use indexmap::IndexMap;
use std::borrow::ToOwned;
use std::default::Default;
use std::fmt::{Debug, Formatter};
use std::io;
use std::io::prelude::*;
use std::io::{BufReader, SeekFrom};
use std::io::{Cursor, ErrorKind};
use std::marker::PhantomData;
use std::mem;
use std::str::{from_utf8, Utf8Error};
use std::sync::Arc;

#[cfg(feature = "deflate-flate2")]
Expand All @@ -40,7 +40,6 @@ use zopfli::Options;

#[cfg(feature = "deflate-zopfli")]
use std::io::BufWriter;
use std::mem::size_of;
use std::path::Path;

#[cfg(feature = "zstd")]
Expand Down Expand Up @@ -703,7 +702,7 @@ impl<A: Read + Write + Seek> ZipWriter<A> {
new_data.is_utf8 = !dest_name.is_ascii();
new_data.header_start = write_position;
let extra_data_start = write_position
+ size_of::<ZipLocalEntryBlock>() as u64
+ mem::size_of::<ZipLocalEntryBlock>() as u64
+ new_data.file_name_raw.len() as u64;
new_data.extra_data_start = Some(extra_data_start);
let mut data_start = extra_data_start;
Expand Down Expand Up @@ -961,8 +960,9 @@ impl<W: Write + Seek> ZipWriter<W> {
),
_ => (options.compression_method, None),
};
let header_end =
header_start + size_of::<ZipLocalEntryBlock>() as u64 + name.to_string().len() as u64;
let header_end = header_start
+ mem::size_of::<ZipLocalEntryBlock>() as u64
+ name.to_string().len() as u64;

if options.alignment > 1 {
let extra_data_end = header_end + extra_data.len() as u64;
Expand Down Expand Up @@ -1535,7 +1535,7 @@ impl<W: Write + Seek> ZipWriter<W> {
writer.seek(SeekFrom::Start(central_start))?;
writer.write_u32_le(0)?;
writer.seek(SeekFrom::Start(
footer_end - size_of::<Zip32CDEBlock>() as u64 - self.comment.len() as u64,
footer_end - mem::size_of::<Zip32CDEBlock>() as u64 - self.comment.len() as u64,
))?;
writer.write_u32_le(0)?;

Expand Down Expand Up @@ -2113,7 +2113,7 @@ fn update_local_zip64_extra_field<T: Write + Seek>(
))?;

let zip64_extra_field_start = file.header_start
+ size_of::<ZipLocalEntryBlock>() as u64
+ mem::size_of::<ZipLocalEntryBlock>() as u64
+ file.file_name_raw.len() as u64;

writer.seek(SeekFrom::Start(zip64_extra_field_start))?;
Expand Down