Debian Codegraph @

src/utils.rs

raw symbols SCIP
1 // Copyright (c) 2023 Harry [Majored] [[email protected]]
2 // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE)
3
4 use crate::error::{Result, ZipError};
5 use futures_lite::io::{AsyncRead, AsyncReadExt};
6
7 // Assert that the next four-byte signature read by a reader which impls AsyncRead matches the expected signature.
8 pub(crate) async fn assert_signature<R: AsyncRead + Unpin>(reader: &mut R, expected: u32) -> Result<()> {
9 let signature = {
10 let mut buffer = [0; 4];
11 reader.read_exact(&mut buffer).await?;
12 u32::from_le_bytes(buffer)
13 };
14 match signature {
15 actual if actual == expected => Ok(()),
16 actual => Err(ZipError::UnexpectedHeaderError(actual, expected)),
17 }
18 }