Code Monkey home page Code Monkey logo

rs-async-zip's Introduction

async_zip

Crates.io Crates.io docs.rs GitHub Workflow Status (branch) GitHub

An asynchronous ZIP archive reading/writing crate powered by tokio.

Features

  • Support for Stored, Deflate, bzip2, LZMA, zstd, and xz compression methods.
  • Various different reading approaches (seek, stream, filesystem, in-memory buffer, etc).
  • Support for writing complete data (u8 slices) or streams using data descriptors.
  • Aims for reasonable specification compliance.

Installation & Basic Usage

[dependencies]
async_zip = { version = "0.0.10", features = ["full"] }

A (soon to be) extensive list of examples can be found under the /examples directory.

Feature Flags

  • chrono - Enables support for parsing dates via chrono.
  • fs - Enables support for the fs reading module.
  • deflate - Enables support for the Deflate compression method.
  • bzip2 - Enables support for the bzip2 compression method.
  • lzma - Enables support for the LZMA compression method.
  • zstd - Enables support for the zstd compression method.
  • xz - Enables support for the xz compression method.

Reading

use tokio::{io::AsyncReadExt, fs::File};
use async_zip::read::seek::ZipFileReader;
...

let mut file = File::open("./Archive.zip").await.unwrap();
let mut zip = ZipFileReader::new(&mut file).await.unwrap();

let entry = zip.file().entries().get(0).unwrap().clone();
let mut string = String::new();
let mut reader = zip.entry(0).await.unwrap();
let txt = reader.read_to_string_checked(&mut string, entry.entry()).await.unwrap();

println!("{}", txt);

Writing

use async_zip::write::ZipFileWriter;
use async_zip::{Compression, ZipEntryBuilder};
use tokio::fs::File;
...

let mut file = File::create("foo.zip").await.unwrap();
let mut writer = ZipFileWriter::new(&mut file);

let data = b"This is an example file.";
let builder = ZipEntryBuilder::new(String::from("bar.txt"), Compression::Deflate);

writer.write_entry_whole(builder, data).await.unwrap();
writer.close().await.unwrap();

Contributions

Whilst I will be continuing to maintain this crate myself, reasonable specification compliance is a huge undertaking for a single individual. As such, contributions will always be encouraged and appreciated.

No contribution guidelines exist but additions should be developed with readability in mind, with appropriate comments, and make use of rustfmt.

Issues & Support

Whether you're wanting to report a bug you've come across during use of this crate or are seeking general help/assistance, please utilise the issues tracker and provide as much detail as possible (eg. recreation steps).

I try to respond to issues within a reasonable timeframe.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.