Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lifthrasiir/rust-zip
A simple rust library for working with ZIP archives
https://github.com/lifthrasiir/rust-zip
Last synced: about 1 month ago
JSON representation
A simple rust library for working with ZIP archives
- Host: GitHub
- URL: https://github.com/lifthrasiir/rust-zip
- Owner: lifthrasiir
- License: mit
- Fork: true (slackito/zip)
- Created: 2014-05-26T04:07:59.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-21T12:08:51.000Z (almost 10 years ago)
- Last Synced: 2024-08-02T08:10:09.701Z (4 months ago)
- Language: Rust
- Size: 399 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust - lifthrasiir/rust-zip - ci.org/lifthrasiir/rust-zip.svg?branch=master">](https://travis-ci.org/lifthrasiir/rust-zip) (代码 / 压缩)
README
# rust-zip [![Build Status](https://travis-ci.org/slackito/zip.svg)](https://travis-ci.org/slackito/zip)
A simple rust library to read and write Zip archives, which is also my pet project for learning Rust.
At the moment you can list the files in a Zip archive, as well as extracting them if they are either stored
(uncompressed) or deflated, but I plan to add write support soon.A simple example
----------------```rust
#![feature(core, os, io, path)]extern crate zip;
use std::os;
use std::old_io::File;
use zip::ZipReader;
use zip::fileinfo::FileInfo;fn main() {
let args = os::args();
match args.len(){
2 => list_content(&mut zip_file(&args[1][])),
3 => extract_file(&mut zip_file(&args[1][]), &args[2][]),
_ => print_usage(&args[0][])
}
}macro_rules! do_or_die{
($expr:expr) => (match $expr {
Ok(val) => val,
Err(err) => {println!("{}",err); panic!()}
})
}fn zip_file(file: &str) -> ZipReader{
do_or_die!(zip::ZipReader::open(&Path::new(file)))
}fn output_file(file: &str)->File{
do_or_die!(File::create(&Path::new(file)))
}fn zipped_file_info(zip: &mut ZipReader, file: &str) -> FileInfo{
do_or_die!(zip.info(file))
}fn list_content(reader: &mut ZipReader)->(){
for file in reader.files(){
let (year, month, day, hour, minute, second) = file.last_modified_datetime;
let mod_time = format!("{:04}-{:02}-{:02} {:02}:{:02}:{:02}", year, month, day, hour, minute, second);
println!("{} ({}): bytes: {:10}, compressed: {:10}",
file.name, mod_time, file.compressed_size, file.uncompressed_size);
}
}fn extract_file(zip: &mut ZipReader, file: &str)->(){
let mut out = output_file(file);
let info = zipped_file_info(zip, file);
do_or_die!(zip.extract(&info, &mut out));
}fn print_usage(this: &str)->(){
println!("Usage: {} [file.zip] [file_to_extract]", this);
}```
TODO
----- Learn more Rust
- Write support
- Create a proper set of tests
- Support advanced features (more compression methods, ZIP64, encryption, multiple volumes...)