Skip to content

Commit

Permalink
Fix magic handling
Browse files Browse the repository at this point in the history
  • Loading branch information
arnauorriols committed May 2, 2024
1 parent 4d9c905 commit ef95708
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ impl EszipV2 {
return Err(ParseError::InvalidV2);
}

Self::parse_with_magic(&magic, reader).await
}

pub(super) async fn parse_with_magic<R: futures::io::AsyncRead + Unpin>(
magic: &[u8],
mut reader: futures::io::BufReader<R>,
) -> Result<
(
EszipV2,
impl Future<Output = Result<futures::io::BufReader<R>, ParseError>>,
),
ParseError,
> {
let supports_npm = magic != *ESZIP_V2_MAGIC;
let supports_options = magic == *ESZIP_V2_2_MAGIC;

Expand Down

0 comments on commit ef95708

Please sign in to comment.