Fix more formatting issues
This commit is contained in:
parent
9330bdb7b7
commit
6dc099d128
3 changed files with 30 additions and 20 deletions
|
@ -4,6 +4,7 @@ use std::io::{Cursor, Write};
|
|||
|
||||
use bencher::Bencher;
|
||||
use zip_next::{ZipArchive, ZipWriter};
|
||||
use zip_next::write::FileOptions;
|
||||
|
||||
const FILE_COUNT: usize = 15_000;
|
||||
const FILE_SIZE: usize = 1024;
|
||||
|
@ -11,9 +12,8 @@ const FILE_SIZE: usize = 1024;
|
|||
fn generate_random_archive(count_files: usize, file_size: usize) -> Vec<u8> {
|
||||
let data = Vec::new();
|
||||
let mut writer = ZipWriter::new(Cursor::new(data));
|
||||
let options =
|
||||
zip_next::write::FileOptions::default()
|
||||
.compression_method(zip_next::CompressionMethod::Stored);
|
||||
let options = FileOptions::default()
|
||||
.compression_method(zip_next::CompressionMethod::Stored);
|
||||
|
||||
let bytes = vec![0u8; file_size];
|
||||
|
||||
|
|
29
src/write.rs
29
src/write.rs
|
@ -1115,10 +1115,7 @@ fn write_local_file_header<T: Write>(writer: &mut T, file: &ZipFileData) -> ZipR
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn update_local_file_header<T: Write + Seek>(
|
||||
writer: &mut T,
|
||||
file: &ZipFileData,
|
||||
) -> ZipResult<()> {
|
||||
fn update_local_file_header<T: Write + Seek>(writer: &mut T, file: &ZipFileData) -> ZipResult<()> {
|
||||
const CRC32_OFFSET: u64 = 14;
|
||||
writer.seek(io::SeekFrom::Start(file.header_start + CRC32_OFFSET))?;
|
||||
writer.write_u32::<LittleEndian>(file.crc32)?;
|
||||
|
@ -1332,9 +1329,9 @@ mod test {
|
|||
use super::{FileOptions, ZipWriter};
|
||||
use crate::compression::CompressionMethod;
|
||||
use crate::types::DateTime;
|
||||
use crate::ZipArchive;
|
||||
use std::io;
|
||||
use std::io::{Read, Write};
|
||||
use crate::ZipArchive;
|
||||
|
||||
#[test]
|
||||
fn write_empty_zip() {
|
||||
|
@ -1473,8 +1470,10 @@ mod test {
|
|||
And I can't stop eating stuff you make me chew\
|
||||
I put on a smile like you wanna see\
|
||||
Another day goes by that I long to be like you";
|
||||
#[cfg(test)] const RT_TEST_FILENAME: &str = "subfolder/sub-subfolder/can't_stop.txt";
|
||||
#[cfg(test)] const SECOND_FILENAME: &str = "different_name.xyz";
|
||||
#[cfg(test)]
|
||||
const RT_TEST_FILENAME: &str = "subfolder/sub-subfolder/can't_stop.txt";
|
||||
#[cfg(test)]
|
||||
const SECOND_FILENAME: &str = "different_name.xyz";
|
||||
|
||||
#[test]
|
||||
fn test_shallow_copy() {
|
||||
|
@ -1488,16 +1487,26 @@ mod test {
|
|||
};
|
||||
writer.start_file(RT_TEST_FILENAME, options).unwrap();
|
||||
writer.write_all(RT_TEST_TEXT.as_ref()).unwrap();
|
||||
writer.shallow_copy_file(RT_TEST_FILENAME, SECOND_FILENAME).unwrap();
|
||||
writer
|
||||
.shallow_copy_file(RT_TEST_FILENAME, SECOND_FILENAME)
|
||||
.unwrap();
|
||||
let zip = writer.finish().unwrap();
|
||||
let mut reader = ZipArchive::new(zip).unwrap();
|
||||
let file_names: Vec<&str> = reader.file_names().collect();
|
||||
assert_eq!(file_names, vec![RT_TEST_FILENAME, SECOND_FILENAME]);
|
||||
let mut first_file_content = String::new();
|
||||
reader.by_name(RT_TEST_FILENAME).unwrap().read_to_string(&mut first_file_content).unwrap();
|
||||
reader
|
||||
.by_name(RT_TEST_FILENAME)
|
||||
.unwrap()
|
||||
.read_to_string(&mut first_file_content)
|
||||
.unwrap();
|
||||
assert_eq!(first_file_content, RT_TEST_TEXT);
|
||||
let mut second_file_content = String::new();
|
||||
reader.by_name(SECOND_FILENAME).unwrap().read_to_string(&mut second_file_content).unwrap();
|
||||
reader
|
||||
.by_name(SECOND_FILENAME)
|
||||
.unwrap()
|
||||
.read_to_string(&mut second_file_content)
|
||||
.unwrap();
|
||||
assert_eq!(second_file_content, RT_TEST_TEXT);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ use std::io::prelude::*;
|
|||
use std::io::{Cursor, Seek};
|
||||
use std::iter::FromIterator;
|
||||
use zip_next::write::FileOptions;
|
||||
use zip_next::{CompressionMethod, SUPPORTED_COMPRESSION_METHODS};
|
||||
use zip_next::{CompressionMethod, SUPPORTED_COMPRESSION_METHODS, ZipWriter};
|
||||
use zip_next::result::ZipResult;
|
||||
|
||||
// This test asserts that after creating a zip file, then reading its contents back out,
|
||||
// the extracted data will *always* be exactly the same as the original data.
|
||||
|
@ -33,7 +34,7 @@ fn copy() {
|
|||
|
||||
{
|
||||
let mut src_archive = zip_next::ZipArchive::new(src_file).unwrap();
|
||||
let mut zip = zip_next::ZipWriter::new(&mut tgt_file);
|
||||
let mut zip = ZipWriter::new(&mut tgt_file);
|
||||
|
||||
{
|
||||
let file = src_archive
|
||||
|
@ -69,7 +70,7 @@ fn append() {
|
|||
write_test_archive(file, method).expect("Couldn't write to test file");
|
||||
|
||||
{
|
||||
let mut zip = zip_next::ZipWriter::new_append(&mut file).unwrap();
|
||||
let mut zip = ZipWriter::new_append(&mut file).unwrap();
|
||||
zip.start_file(
|
||||
COPY_ENTRY_NAME,
|
||||
FileOptions::default().compression_method(method),
|
||||
|
@ -89,8 +90,8 @@ fn append() {
|
|||
fn write_test_archive(
|
||||
file: &mut Cursor<Vec<u8>>,
|
||||
method: CompressionMethod,
|
||||
) -> zip_next::result::ZipResult<()> {
|
||||
let mut zip = zip_next::ZipWriter::new(file);
|
||||
) -> ZipResult<()> {
|
||||
let mut zip = ZipWriter::new(file);
|
||||
|
||||
zip.add_directory("test/", Default::default())?;
|
||||
|
||||
|
@ -116,7 +117,7 @@ fn write_test_archive(
|
|||
}
|
||||
|
||||
// Load an archive from buffer and check for test data.
|
||||
fn check_test_archive<R: Read + Seek>(zip_file: R) -> zip_next::result::ZipResult<zip_next::ZipArchive<R>> {
|
||||
fn check_test_archive<R: Read + Seek>(zip_file: R) -> ZipResult<zip_next::ZipArchive<R>> {
|
||||
let mut archive = zip_next::ZipArchive::new(zip_file).unwrap();
|
||||
|
||||
// Check archive contains expected file names.
|
||||
|
@ -149,7 +150,7 @@ fn check_test_archive<R: Read + Seek>(zip_file: R) -> zip_next::result::ZipResul
|
|||
fn read_archive_file<R: Read + Seek>(
|
||||
archive: &mut zip_next::ZipArchive<R>,
|
||||
name: &str,
|
||||
) -> zip_next::result::ZipResult<String> {
|
||||
) -> ZipResult<String> {
|
||||
let mut file = archive.by_name(name)?;
|
||||
|
||||
let mut contents = String::new();
|
||||
|
|
Loading…
Add table
Reference in a new issue