Skip to content

Commit

Permalink
feat: Resolve winnow + chrono deprecations (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Mar 16, 2024
1 parent 77f7062 commit a26f09d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions rc-zip/src/parse/central_directory_file_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing::trace;
use winnow::{
binary::{le_u16, le_u32},
prelude::PResult,
token::{tag, take},
token::{literal, take},
Parser, Partial,
};

Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'a> CentralDirectoryFileHeader<'a> {

/// Parser for the central directory file header
pub fn parser(i: &mut Partial<&'a [u8]>) -> PResult<Self> {
_ = tag(Self::SIGNATURE).parse_next(i)?;
_ = literal(Self::SIGNATURE).parse_next(i)?;
let creator_version = Version::parser.parse_next(i)?;
let reader_version = Version::parser.parse_next(i)?;
let flags = le_u16.parse_next(i)?;
Expand Down
5 changes: 1 addition & 4 deletions rc-zip/src/parse/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,5 @@ impl NtfsTimestamp {
}

pub(crate) fn zero_datetime() -> chrono::DateTime<chrono::offset::Utc> {
chrono::DateTime::from_naive_utc_and_offset(
chrono::naive::NaiveDateTime::from_timestamp_opt(0, 0).unwrap(),
chrono::offset::Utc,
)
chrono::DateTime::<Utc>::from_timestamp_millis(0).unwrap()
}
8 changes: 4 additions & 4 deletions rc-zip/src/parse/eocd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tracing::trace;
use winnow::{
binary::{le_u16, le_u32, le_u64, length_take},
seq,
token::tag,
token::literal,
PResult, Parser, Partial,
};

Expand Down Expand Up @@ -57,7 +57,7 @@ impl<'a> EndOfCentralDirectoryRecord<'a> {

/// Parser for the end of central directory record
pub fn parser(i: &mut Partial<&'a [u8]>) -> PResult<Self> {
let _ = tag(Self::SIGNATURE).parse_next(i)?;
let _ = literal(Self::SIGNATURE).parse_next(i)?;
seq! {Self {
disk_nbr: le_u16,
dir_disk_nbr: le_u16,
Expand Down Expand Up @@ -89,7 +89,7 @@ impl EndOfCentralDirectory64Locator {

/// Parser for the zip64 end of central directory locator
pub fn parser(i: &mut Partial<&'_ [u8]>) -> PResult<Self> {
_ = tag(Self::SIGNATURE).parse_next(i)?;
_ = literal(Self::SIGNATURE).parse_next(i)?;
seq! {Self {
dir_disk_number: le_u32,
directory_offset: le_u64,
Expand Down Expand Up @@ -136,7 +136,7 @@ impl EndOfCentralDirectory64Record {

/// Parser for the zip64 end of central directory record
pub fn parser(i: &mut Partial<&'_ [u8]>) -> PResult<Self> {
_ = tag(Self::SIGNATURE).parse_next(i)?;
_ = literal(Self::SIGNATURE).parse_next(i)?;
seq! {Self {
record_size: le_u64,
creator_version: le_u16,
Expand Down
4 changes: 2 additions & 2 deletions rc-zip/src/parse/extra_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use winnow::{
combinator::{opt, preceded, repeat_till},
error::{ErrMode, ErrorKind, ParserError, StrContext},
seq,
token::{tag, take},
token::{literal, take},
PResult, Parser, Partial,
};

Expand Down Expand Up @@ -258,7 +258,7 @@ impl ExtraNewUnixField {
const TAG: u16 = 0x7875;

fn parser(i: &mut Partial<&'_ [u8]>) -> PResult<Self> {
let _ = tag("\x01").parse_next(i)?;
let _ = literal("\x01").parse_next(i)?;
seq! {Self {
uid: Self::parse_variable_length_integer,
gid: Self::parse_variable_length_integer,
Expand Down
6 changes: 3 additions & 3 deletions rc-zip/src/parse/local_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use winnow::{
combinator::opt,
error::{ContextError, ErrMode, ErrorKind, FromExternalError},
seq,
token::{tag, take},
token::{literal, take},
PResult, Parser, Partial,
};

Expand Down Expand Up @@ -69,7 +69,7 @@ impl<'a> LocalFileHeader<'a> {

/// Parser for the local file header
pub fn parser(i: &mut Partial<&'a [u8]>) -> PResult<Self> {
let _ = tag(Self::SIGNATURE).parse_next(i)?;
let _ = literal(Self::SIGNATURE).parse_next(i)?;

let reader_version = Version::parser.parse_next(i)?;
let flags = le_u16.parse_next(i)?;
Expand Down Expand Up @@ -204,7 +204,7 @@ impl DataDescriptorRecord {
// MAY be encountered with or without this signature marking data
// descriptors and SHOULD account for either case when reading ZIP files
// to ensure compatibility.
let _ = opt(tag(Self::SIGNATURE)).parse_next(i)?;
let _ = opt(literal(Self::SIGNATURE)).parse_next(i)?;

if is_zip64 {
seq! {Self {
Expand Down

0 comments on commit a26f09d

Please sign in to comment.