9 stable releases

2.0.4 Jan 16, 2022
2.0.2 Apr 23, 2021
1.0.3 Apr 18, 2021
0.1.0 Apr 18, 2021

#427 in Compression

Download history 78/week @ 2024-07-29 142/week @ 2024-08-05 115/week @ 2024-08-12 167/week @ 2024-08-19 108/week @ 2024-08-26 129/week @ 2024-09-02 125/week @ 2024-09-09 126/week @ 2024-09-16 158/week @ 2024-09-23 141/week @ 2024-09-30 239/week @ 2024-10-07 249/week @ 2024-10-14 209/week @ 2024-10-21 145/week @ 2024-10-28 201/week @ 2024-11-04 160/week @ 2024-11-11

717 downloads per month
Used in twtar

MIT/Apache

9KB
166 lines

egzreader

Crates.io Documentation License

Read gzip/non-gzip stream easily in Rust.

Installation

# Cargo.toml
[dependencies]
egzreader = "2"

Example

use std::io::prelude::*;
use std::io;
use std::fs::File;
use egzreader::EgzReader;

fn read_hello() -> io::Result<()> {
    // text file
    let mut r1 = EgzReader::new(
        File::open("examples/hello.txt")?
    );
    // gzip encoded text file
    let mut r2 = EgzReader::new(
        File::open("examples/hello.txt.gz")?
    );

    let mut s1 = String::new();
    let mut s2 = String::new();

    r1.read_to_string(&mut s1)?;
    r2.read_to_string(&mut s2)?;

    assert_eq!(s1, "Hello!");
    assert_eq!(s2, "Hello!");

    Ok(())
}

lib.rs:

Read gzip/non-gzip stream easily.

EgzReader decodes the underlying reader when it is gzipped stream, and reads as it is when non-gzipped.

Examples

use std::io::prelude::*;
use std::io;
use std::fs::File;
use egzreader::EgzReader;

fn read_hello() -> io::Result<()> {
    // text file
    let mut r1 = EgzReader::new(
        File::open("examples/hello.txt")?
    );
    // gzip encoded text file
    let mut r2 = EgzReader::new(
        File::open("examples/hello.txt.gz")?
    );

    let mut s1 = String::new();
    let mut s2 = String::new();

    r1.read_to_string(&mut s1)?;
    r2.read_to_string(&mut s2)?;

    assert_eq!(s1, "Hello!");
    assert_eq!(s2, "Hello!");

    Ok(())
}

Dependencies

~320KB