Skip to content

Commit 527bda9

Browse files
committed
Revert "Introduce tracing, add util functions, add core raw macro, add core lfh logic"
This reverts commit f60a9d5.
1 parent f60a9d5 commit 527bda9

File tree

5 files changed

+10
-145
lines changed

5 files changed

+10
-145
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ crc32fast = "1"
3838
futures-lite = { version = "2.1.0", default-features = false, features = ["std"] }
3939
pin-project = "1"
4040
thiserror = "1"
41-
tracing = "0.1.40"
4241

4342
async-compression = { version = "0.4.2", default-features = false, features = ["futures-io"], optional = true }
4443
chrono = { version = "0.4", default-features = false, features = ["clock"], optional = true }

src/core/lfh.rs

-67
This file was deleted.

src/core/mod.rs

-33
This file was deleted.

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
3939
pub mod base;
4040
pub mod error;
41-
pub mod core;
4241

4342
#[cfg(feature = "tokio")]
4443
pub mod tokio;

src/utils.rs

+10-43
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,17 @@
22
// MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE)
33

44
use crate::error::{Result, ZipError};
5-
use futures_lite::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
5+
use futures_lite::io::{AsyncRead, AsyncReadExt};
66

77
// Assert that the next four-byte signature read by a reader which impls AsyncRead matches the expected signature.
8-
#[tracing::instrument(skip(reader))]
9-
pub(crate) async fn assert_signature(reader: impl AsyncRead + Unpin, expected: u32) -> Result<()> {
10-
let actual = read_u32(reader).await?;
11-
12-
if actual != expected {
13-
return Err(ZipError::UnexpectedHeaderError(actual, expected));
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)),
1417
}
15-
16-
Ok(())
17-
}
18-
19-
#[tracing::instrument(skip(reader))]
20-
pub(crate) async fn read_u16(mut reader: impl AsyncRead + Unpin) -> Result<u16> {
21-
let mut buf = [0u8; 2];
22-
reader.read_exact(&mut buf).await.unwrap();
23-
Ok(u16::from_le_bytes(buf))
24-
}
25-
26-
#[tracing::instrument(skip(reader))]
27-
pub(crate) async fn read_u32(mut reader: impl AsyncRead + Unpin) -> Result<u32> {
28-
let mut buf = [0u8; 4];
29-
reader.read_exact(&mut buf).await.unwrap();
30-
Ok(u32::from_le_bytes(buf))
31-
}
32-
33-
#[tracing::instrument(skip(writer))]
34-
pub(crate) async fn write_u16(mut writer: impl AsyncWrite + Unpin, value: u16) -> Result<()> {
35-
writer.write_all(&value.to_be_bytes()).await?;
36-
Ok(())
37-
}
38-
39-
#[tracing::instrument(skip(writer))]
40-
pub(crate) async fn write_u32(mut writer: impl AsyncWrite + Unpin, value: u32) -> Result<()> {
41-
writer.write_all(&value.to_be_bytes()).await?;
42-
Ok(())
43-
}
44-
45-
/// Read and return a dynamic length vector of bytes from a reader which impls AsyncRead.
46-
#[tracing::instrument(skip(reader))]
47-
pub(crate) async fn read_bytes(reader: impl AsyncRead + Unpin, length: usize) -> Result<Vec<u8>> {
48-
let mut buffer = Vec::with_capacity(length);
49-
reader.take(length as u64).read_to_end(&mut buffer).await?;
50-
Ok(buffer)
5118
}

0 commit comments

Comments
 (0)