Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from circular to oval #47

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/rc-zip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["compression"]
[dependencies]
nom = "7.1.3"
pretty-hex = "0.4.1"
circular = "0.3.0"
oval = "1.0.0"
chrono = "0.4.33"
encoding_rs = "0.8.33"
crc32fast = "1.3.2"
Expand Down
6 changes: 3 additions & 3 deletions crates/rc-zip/src/reader/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ use std::io::Read;

use tracing::trace;

/// A wrapper around [circular::Buffer] that keeps track of how many bytes we've read since
/// A wrapper around [oval::Buffer] that keeps track of how many bytes we've read since
/// initialization or the last reset.
pub(crate) struct Buffer {
pub(crate) buffer: circular::Buffer,
pub(crate) buffer: oval::Buffer,
pub(crate) read_bytes: u64,
}

impl Buffer {
/// creates a new buffer with the specified capacity
pub(crate) fn with_capacity(size: usize) -> Self {
Self {
buffer: circular::Buffer::with_capacity(size),
buffer: oval::Buffer::with_capacity(size),
read_bytes: 0,
}
}
Expand Down
12 changes: 7 additions & 5 deletions crates/rc-zip/src/reader/sync/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{cmp, io};

use oval::Buffer;

pub trait Decoder<R>: io::Read
where
R: io::Read,
Expand Down Expand Up @@ -50,23 +52,23 @@ where
}
}

/// Only allows reading a fixed number of bytes from a [circular::Buffer],
/// Only allows reading a fixed number of bytes from a [oval::Buffer],
/// allowing to move the inner reader out afterwards.
pub struct LimitedReader {
remaining: u64,
inner: circular::Buffer,
inner: Buffer,
}

impl LimitedReader {
pub fn new(inner: circular::Buffer, remaining: u64) -> Self {
pub fn new(inner: Buffer, remaining: u64) -> Self {
Self { inner, remaining }
}

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

pub fn get_mut(&mut self) -> &mut circular::Buffer {
pub fn get_mut(&mut self) -> &mut Buffer {
&mut self.inner
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/rc-zip/src/reader/sync/entry_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod deflate64_dec;

use cfg_if::cfg_if;
use nom::Offset;
use oval::Buffer;
use std::io;
use tracing::trace;

Expand All @@ -28,7 +29,7 @@ struct EntryReadMetrics {

enum State {
ReadLocalHeader {
buffer: circular::Buffer,
buffer: Buffer,
},
ReadData {
hasher: crc32fast::Hasher,
Expand All @@ -39,7 +40,7 @@ enum State {
ReadDataDescriptor {
metrics: EntryReadMetrics,
header: LocalFileHeaderRecord,
buffer: circular::Buffer,
buffer: Buffer,
},
Validate {
metrics: EntryReadMetrics,
Expand Down Expand Up @@ -256,7 +257,7 @@ where
rd: EOFNormalizer::new(get_reader(entry.header_offset)),
eof: false,
state: State::ReadLocalHeader {
buffer: circular::Buffer::with_capacity(Self::DEFAULT_BUFFER_SIZE),
buffer: Buffer::with_capacity(Self::DEFAULT_BUFFER_SIZE),
},
method: entry.method(),
inner: entry.inner,
Expand Down
Loading