Skip to content

Commit b72585c

Browse files
committed
Merge branch 'fix-some-imports' of github.com:Its-Just-Nans/zip2 into fix-some-imports
2 parents 932580e + 8e51773 commit b72585c

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ zeroize = { version = "1.8", optional = true, features = ["zeroize_derive"] }
5050
zstd = { version = "0.13", optional = true, default-features = false }
5151
zopfli = { version = "0.8", optional = true }
5252
deflate64 = { version = "0.1.9", optional = true }
53-
lzma-rust2 = { version = "0.13", optional = true, default-features = false, features = ["std", "encoder", "optimization", "xz"] }
54-
bitstream-io = { version = "4.5.0", optional = true }
53+
lzma-rust2 = { version = "0.15", optional = true, default-features = false, features = ["std", "encoder", "optimization", "xz"] }
54+
bitstream-io = { version = "4.5.0", optional = true }
5555

5656
[target.'cfg(fuzzing)'.dependencies]
5757
arbitrary = { version = "1.4.1", features = ["derive"] }

src/spec.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,28 @@ impl ExtraFieldMagic {
111111
///
112112
/// let big_len: usize = (zip::ZIP64_BYTES_THR as usize) + 1;
113113
/// let big_buf = vec![0u8; big_len];
114+
/// {
114115
/// zip.start_file("zero.dat", options)?;
115116
/// // This is too big!
116117
/// let res = zip.write_all(&big_buf[..]).err().unwrap();
117118
/// assert_eq!(res.kind(), io::ErrorKind::Other);
118119
/// let description = format!("{}", &res);
119120
/// assert_eq!(description, "Large file option has not been set");
121+
/// }
122+
/// {
120123
/// // Attempting to write anything further to the same zip will still succeed, but the previous
121124
/// // failing entry has been removed.
122125
/// zip.start_file("one.dat", options)?;
123126
/// let zip = zip.finish_into_readable()?;
124127
/// let names: Vec<_> = zip.file_names().collect();
125128
/// assert_eq!(&names, &["one.dat"]);
129+
/// }
126130
///
127131
/// // Create a new zip output.
128132
/// let mut zip = ZipWriter::new(Cursor::new(Vec::new()));
129133
/// // This time, create a zip64 record for the file.
130-
/// let options = options.large_file(true);
134+
/// let options = SimpleFileOptions::default()
135+
/// .compression_method(zip::CompressionMethod::Stored).large_file(true);
131136
/// zip.start_file("zero.dat", options)?;
132137
/// // This succeeds because we specified that it could be a large file.
133138
/// assert!(zip.write_all(&big_buf[..]).is_ok());

src/types.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -974,17 +974,23 @@ impl ZipFileData {
974974
)
975975
}
976976

977-
pub(crate) fn data_descriptor_block(&self) -> Option<ZipDataDescriptorBlock> {
977+
pub(crate) fn write_data_descriptor<W: std::io::Write>(
978+
&self,
979+
writer: &mut W,
980+
) -> Result<(), ZipError> {
978981
if self.large_file {
979-
return None;
982+
return self.zip64_data_descriptor_block().write(writer);
980983
}
984+
self.data_descriptor_block().write(writer)
985+
}
981986

982-
Some(ZipDataDescriptorBlock {
987+
pub(crate) fn data_descriptor_block(&self) -> ZipDataDescriptorBlock {
988+
ZipDataDescriptorBlock {
983989
magic: ZipDataDescriptorBlock::MAGIC,
984990
crc32: self.crc32,
985991
compressed_size: self.compressed_size as u32,
986992
uncompressed_size: self.uncompressed_size as u32,
987-
})
993+
}
988994
}
989995

990996
pub(crate) fn zip64_data_descriptor_block(&self) -> Zip64DataDescriptorBlock {

src/write.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ impl<W: Write + Seek> ZipWriter<W> {
10751075
};
10761076
update_aes_extra_data(writer, file)?;
10771077
if file.using_data_descriptor {
1078-
write_data_descriptor(writer, file)?;
1078+
file.write_data_descriptor(writer)?;
10791079
} else {
10801080
update_local_file_header(writer, file)?;
10811081
writer.seek(SeekFrom::Start(file_end))?;
@@ -2004,23 +2004,6 @@ fn update_aes_extra_data<W: Write + Seek>(writer: &mut W, file: &mut ZipFileData
20042004
Ok(())
20052005
}
20062006

2007-
fn write_data_descriptor<T: Write>(writer: &mut T, file: &ZipFileData) -> ZipResult<()> {
2008-
if let Some(block) = file.data_descriptor_block() {
2009-
block.write(writer)?;
2010-
} else {
2011-
// check compressed size as well as it can also be slightly larger than uncompressed size
2012-
if file.compressed_size > spec::ZIP64_BYTES_THR {
2013-
return Err(ZipError::Io(io::Error::other(
2014-
"Large file option has not been set",
2015-
)));
2016-
}
2017-
2018-
file.zip64_data_descriptor_block().write(writer)?;
2019-
}
2020-
2021-
Ok(())
2022-
}
2023-
20242007
fn update_local_file_header<T: Write + Seek>(
20252008
writer: &mut T,
20262009
file: &mut ZipFileData,

0 commit comments

Comments
 (0)