diff --git a/Cargo.lock b/Cargo.lock index ebfb853..6ccc0a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -166,7 +175,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -392,6 +401,15 @@ dependencies = [ "crc", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.7.1" @@ -460,7 +478,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -622,8 +640,53 @@ dependencies = [ "pretty-hex", "thiserror", "tracing", + "tracing-test", ] +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.5", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.2", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + [[package]] name = "ryu" version = "1.0.16" @@ -647,7 +710,7 @@ checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -688,6 +751,17 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.48" @@ -716,7 +790,7 @@ checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -765,7 +839,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -795,14 +869,41 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] +[[package]] +name = "tracing-test" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a2c0ff408fe918a94c428a3f2ad04e4afd5c95bbc08fcf868eff750c15728a4" +dependencies = [ + "lazy_static", + "tracing-core", + "tracing-subscriber", + "tracing-test-macro", +] + +[[package]] +name = "tracing-test-macro" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bc1c4f8e2e73a977812ab339d503e6feeb92700f6d07a6de4d321522d5c08" +dependencies = [ + "lazy_static", + "quote", + "syn 1.0.109", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -848,7 +949,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -870,7 +971,7 @@ checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/crates/rc-zip/Cargo.toml b/crates/rc-zip/Cargo.toml index eba8fcb..b1343e1 100644 --- a/crates/rc-zip/Cargo.toml +++ b/crates/rc-zip/Cargo.toml @@ -35,3 +35,6 @@ sync = [] file = ["positioned-io"] deflate = ["flate2"] lzma = ["lzma-rs"] + +[dev-dependencies] +tracing-test = "0.2.4" diff --git a/crates/rc-zip/src/reader/sync/entry_reader/lzma_dec.rs b/crates/rc-zip/src/reader/sync/entry_reader/lzma_dec.rs index d2dad5b..eb9d687 100644 --- a/crates/rc-zip/src/reader/sync/entry_reader/lzma_dec.rs +++ b/crates/rc-zip/src/reader/sync/entry_reader/lzma_dec.rs @@ -79,8 +79,9 @@ where dst_slice.copy_from_slice(src_slice); } - // TODO: use a ring buffer instead - *write_buf = write_buf.split_off(write_count); + // copy the remaining bytes to the front of the buffer + write_buf.rotate_left(write_count); + write_buf.truncate(write_buf.len() - write_count); self.total_write_count += write_count as u64; Ok(write_count) diff --git a/crates/rc-zip/src/tests.rs b/crates/rc-zip/src/tests.rs index 05787ff..2f08ea5 100644 --- a/crates/rc-zip/src/tests.rs +++ b/crates/rc-zip/src/tests.rs @@ -1,3 +1,5 @@ +use tracing_test::traced_test; + use crate::{ reader::sync::{HasCursor, SyncArchive, SyncStoredEntry}, Archive, @@ -286,6 +288,7 @@ fn test_cases() -> Vec { } #[test] +#[traced_test] fn read_from_slice() { let bytes = std::fs::read(zips_dir().join("test.zip")).unwrap(); let slice = &bytes[..]; @@ -294,6 +297,7 @@ fn read_from_slice() { } #[test] +#[traced_test] fn read_from_file() { let f = File::open(zips_dir().join("test.zip")).unwrap(); let archive = f.read_zip().unwrap(); @@ -301,6 +305,7 @@ fn read_from_file() { } #[test] +#[traced_test] fn real_world_files() { for case in test_cases() { case.check(case.bytes().read_zip()); @@ -308,6 +313,7 @@ fn real_world_files() { } #[test] +#[traced_test] fn test_fsm() { use super::reader::{ArchiveReader, ArchiveReaderResult};