Skip to content

Commit

Permalink
Revert "Introduce tracing, add util functions, add core raw macro, ad…
Browse files Browse the repository at this point in the history
…d core lfh logic"

This reverts commit f60a9d5.
  • Loading branch information
Majored committed Oct 27, 2024
1 parent f60a9d5 commit 527bda9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 145 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ crc32fast = "1"
futures-lite = { version = "2.1.0", default-features = false, features = ["std"] }
pin-project = "1"
thiserror = "1"
tracing = "0.1.40"

async-compression = { version = "0.4.2", default-features = false, features = ["futures-io"], optional = true }
chrono = { version = "0.4", default-features = false, features = ["clock"], optional = true }
Expand Down
67 changes: 0 additions & 67 deletions src/core/lfh.rs

This file was deleted.

33 changes: 0 additions & 33 deletions src/core/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
pub mod base;
pub mod error;
pub mod core;

#[cfg(feature = "tokio")]
pub mod tokio;
Expand Down
53 changes: 10 additions & 43 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,17 @@
// MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE)

use crate::error::{Result, ZipError};
use futures_lite::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use futures_lite::io::{AsyncRead, AsyncReadExt};

// Assert that the next four-byte signature read by a reader which impls AsyncRead matches the expected signature.
#[tracing::instrument(skip(reader))]
pub(crate) async fn assert_signature(reader: impl AsyncRead + Unpin, expected: u32) -> Result<()> {
let actual = read_u32(reader).await?;

if actual != expected {
return Err(ZipError::UnexpectedHeaderError(actual, expected));
pub(crate) async fn assert_signature<R: AsyncRead + Unpin>(reader: &mut R, expected: u32) -> Result<()> {
let signature = {
let mut buffer = [0; 4];
reader.read_exact(&mut buffer).await?;
u32::from_le_bytes(buffer)
};
match signature {
actual if actual == expected => Ok(()),
actual => Err(ZipError::UnexpectedHeaderError(actual, expected)),
}

Ok(())
}

#[tracing::instrument(skip(reader))]
pub(crate) async fn read_u16(mut reader: impl AsyncRead + Unpin) -> Result<u16> {
let mut buf = [0u8; 2];
reader.read_exact(&mut buf).await.unwrap();
Ok(u16::from_le_bytes(buf))
}

#[tracing::instrument(skip(reader))]
pub(crate) async fn read_u32(mut reader: impl AsyncRead + Unpin) -> Result<u32> {
let mut buf = [0u8; 4];
reader.read_exact(&mut buf).await.unwrap();
Ok(u32::from_le_bytes(buf))
}

#[tracing::instrument(skip(writer))]
pub(crate) async fn write_u16(mut writer: impl AsyncWrite + Unpin, value: u16) -> Result<()> {
writer.write_all(&value.to_be_bytes()).await?;
Ok(())
}

#[tracing::instrument(skip(writer))]
pub(crate) async fn write_u32(mut writer: impl AsyncWrite + Unpin, value: u32) -> Result<()> {
writer.write_all(&value.to_be_bytes()).await?;
Ok(())
}

/// Read and return a dynamic length vector of bytes from a reader which impls AsyncRead.
#[tracing::instrument(skip(reader))]
pub(crate) async fn read_bytes(reader: impl AsyncRead + Unpin, length: usize) -> Result<Vec<u8>> {
let mut buffer = Vec::with_capacity(length);
reader.take(length as u64).read_to_end(&mut buffer).await?;
Ok(buffer)
}

0 comments on commit 527bda9

Please sign in to comment.