Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Dec 18, 2024
1 parent d1ccb08 commit 2353489
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions rc-zip-monoio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ use rc_zip::{

pub async fn read_zip_from_file(file: &File) -> Result<Archive, Error> {
let meta = file.metadata().await?;

let size = meta.len();
let mut buf = vec![0u8; 128 * 1024];
let mut fsm = ArchiveFsm::new(meta.len());

let mut fsm = ArchiveFsm::new(size);
loop {
if let Some(offset) = fsm.wants_read() {
let dst = fsm.space();
let max_read = dst.len();
let max_read = dst.len().min(buf.len());
let slice = IoBufMut::slice_mut(buf, 0..max_read);

let (res, slice) = file.read_at(slice, offset).await;
let n = res?;

let src = &slice[..n];
let dst = &mut dst[..n];
dst.copy_from_slice(src);
(dst[..n]).copy_from_slice(&slice[..n]);

fsm.fill(n);
buf = slice.into_inner();
Expand Down

0 comments on commit 2353489

Please sign in to comment.