From ef95708cef50ab511a0d9aa4465006e69e2be8b8 Mon Sep 17 00:00:00 2001 From: Arnau Orriols Date: Thu, 2 May 2024 08:52:15 +0200 Subject: [PATCH] Fix magic handling --- src/lib.rs | 2 +- src/v2.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8ffc61a..ae21c64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,7 +46,7 @@ impl Eszip { let mut magic = [0; 8]; reader.read_exact(&mut magic).await?; if EszipV2::has_magic(&magic) { - let (eszip, fut) = EszipV2::parse(reader).await?; + let (eszip, fut) = EszipV2::parse_with_magic(&magic, reader).await?; Ok((Eszip::V2(eszip), Box::pin(fut))) } else { let mut buffer = Vec::new(); diff --git a/src/v2.rs b/src/v2.rs index 835a08e..f2aff3c 100644 --- a/src/v2.rs +++ b/src/v2.rs @@ -312,6 +312,19 @@ impl EszipV2 { return Err(ParseError::InvalidV2); } + Self::parse_with_magic(&magic, reader).await + } + + pub(super) async fn parse_with_magic( + magic: &[u8], + mut reader: futures::io::BufReader, + ) -> Result< + ( + EszipV2, + impl Future, ParseError>>, + ), + ParseError, + > { let supports_npm = magic != *ESZIP_V2_MAGIC; let supports_options = magic == *ESZIP_V2_2_MAGIC;