-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve reading from non-seekable streams
You can now repeatedly call a function to iterate over all files in a zip. This may give some suboptimal results, but is useful when dealing with an incoming data stream.
- Loading branch information
Showing
3 changed files
with
138 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extern crate zip; | ||
|
||
use std::io; | ||
|
||
fn main() { | ||
std::process::exit(real_main()); | ||
} | ||
|
||
fn real_main() -> i32 { | ||
let stdin = io::stdin(); | ||
let mut stdin_handle = stdin.lock(); | ||
|
||
loop { | ||
match zip::read::read_zipfile_from_stream(&mut stdin_handle) { | ||
Ok(None) => break, | ||
Ok(Some(file)) => { | ||
println!("{}: {} bytes ({} bytes packed)", file.name(), file.size(), file.compressed_size()); | ||
}, | ||
Err(e) => { | ||
println!("Error encountered while reading zip: {:?}", e); | ||
return 1; | ||
}, | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters