Skip to content

Commit

Permalink
Split sync/tokio into their own separate crates
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Feb 1, 2024
1 parent f91c604 commit 1413e7a
Show file tree
Hide file tree
Showing 79 changed files with 458 additions and 513 deletions.
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"rust-analyzer.cargo.features": [
"default",
"tokio",
"lzma",
"deflate64",
"bzip2",
Expand Down
84 changes: 62 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 7 additions & 67 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,67 +1,7 @@
[package]
name = "rc-zip"
version = "2.0.1"
description = "zip reading"
repository = "https://github.com/fasterthanlime/rc-zip"
license = "Apache-2.0 OR MIT"
authors = ["Amos Wenger <[email protected]>"]
edition = "2021"
readme = "README.md"

keywords = ["zip", "unzip"]
categories = ["compression"]

[lib]
name = "rc_zip"
path = "src/lib.rs"

[[example]]
name = "jean"
path = "examples/jean/src/main.rs"

[dependencies]
winnow = "0.5.36"
pretty-hex = "0.4.1"
oval = "2.0.0"
chrono = "0.4.33"
encoding_rs = "0.8.33"
crc32fast = "1.3.2"
positioned-io = { version = "0.3.3", optional = true }
tracing = "0.1.40"
oem_cp = "2.0.0"
thiserror = "1.0.56"
chardetng = "0.1.17"
flate2 = { version = "1.0.28", optional = true }
num_enum = "0.7.2"
byteorder = "1.5.0"
cfg-if = "1.0.0"
lzma-rs = { version = "0.3.0", features = ["stream"], optional = true }
deflate64 = { version = "0.1.7", optional = true }
bzip2 = { version = "0.4.4", optional = true }
zstd = { version = "0.13.0", optional = true }
tokio = { version = "1.35.1", optional = true, features = ["fs", "io-util", "rt-multi-thread"] }
futures = { version = "0.3.30", optional = true }
pin-project-lite = { version = "0.2.13", optional = true }
async-compression = { version = "0.4.6", optional = true, features = ["tokio", "deflate"] }

[features]
default = ["sync", "file", "deflate"]
sync = []
file = ["positioned-io"]
deflate = ["dep:flate2"]
deflate64 = ["dep:deflate64"]
lzma = ["dep:lzma-rs"]
bzip2 = ["dep:bzip2"]
zstd = ["dep:zstd"]
tokio = ["dep:tokio", "dep:futures", "dep:pin-project-lite", "async-compression"]

[dev-dependencies]
clap = { version = "4.4.18", features = ["derive"] }
humansize = "2.1.3"
indicatif = "0.17.7"
test-log = { version = "0.2.14", default-features = false, features = ["tracing-subscriber", "trace"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tokio = { version = "1.35.1", features = ["macros"] }

[profile.release]
debug = 1
[workspace]
resolver = "2"
members = [
"rc-zip",
"rc-zip-sync",
"rc-zip-tokio",
]
2 changes: 0 additions & 2 deletions codecov.yml

This file was deleted.

2 changes: 0 additions & 2 deletions examples/jean/.gitignore

This file was deleted.

23 changes: 0 additions & 23 deletions examples/jean/Cargo.toml

This file was deleted.

52 changes: 52 additions & 0 deletions rc-zip-sync/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "rc-zip-sync"
version = "2.0.1"
description = "Synchronous zip reading on top of rc-zip"
repository = "https://github.com/fasterthanlime/rc-zip"
license = "Apache-2.0 or MIT"
authors = ["Amos Wenger <[email protected]>"]
edition = "2021"
readme = "README.md"

keywords = ["zip", "unzip"]
categories = ["compression"]

[lib]
name = "rc_zip_sync"
path = "src/lib.rs"

[[example]]
name = "jean"
path = "examples/jean.rs"

[dependencies]
positioned-io = { version = "0.3.3", optional = true }
flate2 = { version = "1.0.28", optional = true }
rc-zip = { version = "2.0.1", path = "../rc-zip" }
lzma-rs = { version = "0.3.0", features = ["stream"], optional = true }
deflate64 = { version = "0.1.7", optional = true }
bzip2 = { version = "0.4.4", optional = true }
zstd = { version = "0.13.0", optional = true }
oval = "2.0.0"
crc32fast = "1.3.2"
tracing = "0.1.40"
byteorder = "1.5.0"
cfg-if = "1.0.0"
winnow = "0.5.36"

[features]
default = ["file", "deflate"]
file = ["positioned-io"]
deflate = ["dep:flate2"]
deflate64 = ["dep:deflate64"]
lzma = ["dep:lzma-rs"]
bzip2 = ["dep:bzip2"]
zstd = ["dep:zstd"]

[dev-dependencies]
chrono = "0.4.33"
clap = { version = "4.4.18", features = ["derive"] }
humansize = "2.1.3"
indicatif = "0.17.7"
test-log = { version = "0.2.14", default-features = false, features = ["tracing-subscriber", "trace"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
3 changes: 2 additions & 1 deletion examples/jean/src/main.rs → rc-zip-sync/examples/jean.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use cfg_if::cfg_if;
use clap::{Parser, Subcommand};
use humansize::{format_size, BINARY};
use rc_zip::{prelude::*, EntryContents};
use rc_zip::EntryContents;
use rc_zip_sync::ReadZip;

use std::{
borrow::Cow,
Expand Down
25 changes: 24 additions & 1 deletion src/reader/sync/decoder.rs → rc-zip-sync/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,30 @@ use std::{cmp, io};

use oval::Buffer;

use crate::reader::RawEntryReader;
/// Only allows reading a fixed number of bytes from a [oval::Buffer],
/// used for reading the raw (compressed) data for a single zip file entry.
/// It also allows moving out the inner buffer afterwards.
pub(crate) struct RawEntryReader {
remaining: u64,
inner: Buffer,
}

impl RawEntryReader {
pub(crate) fn new(inner: Buffer, entry_size: u64) -> Self {
Self {
inner,
remaining: entry_size,
}
}

pub(crate) fn into_inner(self) -> Buffer {
self.inner
}

pub(crate) fn get_mut(&mut self) -> &mut Buffer {
&mut self.inner
}
}

pub(crate) trait Decoder<R>: io::Read
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::Read;

use bzip2::read::BzDecoder;

use crate::reader::{sync::decoder::Decoder, RawEntryReader};
use crate::decoder::{Decoder, RawEntryReader};

impl<R> Decoder<R> for BzDecoder<R>
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::{BufReader, Read};

use deflate64::Deflate64Decoder;

use crate::reader::{sync::decoder::Decoder, RawEntryReader};
use crate::decoder::{Decoder, RawEntryReader};

impl<R> Decoder<R> for Deflate64Decoder<BufReader<R>>
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::Read;

use flate2::read::DeflateDecoder;

use crate::reader::{sync::decoder::Decoder, RawEntryReader};
use crate::decoder::{Decoder, RawEntryReader};

impl<R> Decoder<R> for DeflateDecoder<R>
where
Expand Down
Loading

0 comments on commit 1413e7a

Please sign in to comment.