refactor: replace the podio crate with byteorder

This commit is contained in:
Marli Frost 2020-06-16 18:59:13 +01:00
parent b36340e779
commit 9ed6904383
No known key found for this signature in database
GPG key ID: CB0BEA7CF9BD1245
4 changed files with 16 additions and 10 deletions

View file

@ -15,7 +15,7 @@ edition = "2018"
[dependencies]
flate2 = { version = "1.0", default-features = false, optional = true }
time = { version = "0.1", optional = true }
podio = "0.1"
byteorder = "1.3.4"
bzip2 = { version = "0.3", optional = true }
crc32fast = "1.0"
thiserror = "1.0"

View file

@ -11,7 +11,7 @@ use std::io::prelude::*;
use crate::cp437::FromCp437;
use crate::types::{DateTime, System, ZipFileData};
use podio::{LittleEndian, ReadPodExt};
use byteorder::{LittleEndian, ReadBytesExt};
#[cfg(feature = "deflate")]
use flate2::read::DeflateDecoder;
@ -341,9 +341,12 @@ fn central_header_to_zip_file<R: Read + io::Seek>(
let _internal_file_attributes = reader.read_u16::<LittleEndian>()?;
let external_file_attributes = reader.read_u32::<LittleEndian>()?;
let offset = reader.read_u32::<LittleEndian>()? as u64;
let file_name_raw = ReadPodExt::read_exact(reader, file_name_length)?;
let extra_field = ReadPodExt::read_exact(reader, extra_field_length)?;
let file_comment_raw = ReadPodExt::read_exact(reader, file_comment_length)?;
let mut file_name_raw = vec![0; file_name_length];
reader.read_exact(&mut file_name_raw)?;
let mut extra_field = vec![0; extra_field_length];
reader.read_exact(&mut extra_field)?;
let mut file_comment_raw = vec![0; file_comment_length];
reader.read_exact(&mut file_comment_raw)?;
let file_name = match is_utf8 {
true => String::from_utf8_lossy(&*file_name_raw).into_owned(),
@ -621,8 +624,10 @@ pub fn read_zipfile_from_stream<'a, R: io::Read>(
let file_name_length = reader.read_u16::<LittleEndian>()? as usize;
let extra_field_length = reader.read_u16::<LittleEndian>()? as usize;
let file_name_raw = ReadPodExt::read_exact(reader, file_name_length)?;
let extra_field = ReadPodExt::read_exact(reader, extra_field_length)?;
let mut file_name_raw = vec![0; file_name_length];
reader.read_exact(&mut file_name_raw)?;
let mut extra_field = vec![0; extra_field_length];
reader.read_exact(&mut extra_field)?;
let file_name = match is_utf8 {
true => String::from_utf8_lossy(&*file_name_raw).into_owned(),

View file

@ -1,5 +1,5 @@
use crate::result::{ZipError, ZipResult};
use podio::{LittleEndian, ReadPodExt, WritePodExt};
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use std::io;
use std::io::prelude::*;
@ -32,7 +32,8 @@ impl CentralDirectoryEnd {
let central_directory_size = reader.read_u32::<LittleEndian>()?;
let central_directory_offset = reader.read_u32::<LittleEndian>()?;
let zip_file_comment_length = reader.read_u16::<LittleEndian>()? as usize;
let zip_file_comment = ReadPodExt::read_exact(reader, zip_file_comment_length)?;
let mut zip_file_comment = vec![0; zip_file_comment_length];
reader.read_exact(&mut zip_file_comment)?;
Ok(CentralDirectoryEnd {
disk_number,

View file

@ -4,8 +4,8 @@ use crate::compression::CompressionMethod;
use crate::result::{ZipError, ZipResult};
use crate::spec;
use crate::types::{DateTime, System, ZipFileData, DEFAULT_VERSION};
use byteorder::{LittleEndian, WriteBytesExt};
use crc32fast::Hasher;
use podio::{LittleEndian, WritePodExt};
use std::default::Default;
use std::io;
use std::io::prelude::*;