Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sile/libflate
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.4.0
Choose a base ref
...
head repository: sile/libflate
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 16 commits
  • 28 files changed
  • 4 contributors

Commits on May 21, 2023

  1. Refactor test case

    sile committed May 21, 2023
    Copy the full SHA
    ed89e1d View commit details

Commits on May 23, 2023

  1. Copy the full SHA
    46b3674 View commit details

Commits on May 24, 2023

  1. Merge pull request #73 from olback/specify-clap-version

    specify clap version in flate_bench
    sile authored May 24, 2023
    Copy the full SHA
    33566f7 View commit details

Commits on Jul 8, 2023

  1. Turn the no_std feature into default-enabled std

    This also:
    - fixes the `no_std` not being enabled due to a swapped `cfg_attr`.
    - tests this builds with a `#![no_std]` binary.
    - A lot of the cfg's have been removed due to being unneeded.
    - adds a new dependency
    - updates the version to 2.0
    - adds a ci command to to use cargo-no-std to check no-std
    
    Some notes on changes from #68:
    
    Everything in `core` is a subset of things in `std`.
    `core` is available in `std` environments, so if you're building
    a `no_std`-compatible library, it's best to import things that
    don't _require_ `std` from `core.
    
    core2 is also meant to be used as a `no_std` polyfill with its
    `std` feature. That is, you can reference `core2::io`, and if the
    `std` feature is enabled, it actually references `std::io`.
    kupiakos committed Jul 8, 2023
    Copy the full SHA
    ee29897 View commit details
  2. Merge pull request #74 from kupiakos/master

    Turn the no_std feature into default-enabled std
    sile authored Jul 8, 2023
    Copy the full SHA
    cc5fb68 View commit details
  3. Update README.md

    sile committed Jul 8, 2023
    Copy the full SHA
    8284efa View commit details
  4. Update edition to 2021

    sile committed Jul 8, 2023
    Copy the full SHA
    cc398ea View commit details
  5. Update Cargo.toml

    sile committed Jul 8, 2023
    Copy the full SHA
    015cf03 View commit details
  6. Update Cargo.toml

    sile committed Jul 8, 2023
    Copy the full SHA
    7aba1f6 View commit details
  7. Fix broken tests

    sile committed Jul 8, 2023
    Copy the full SHA
    40d8260 View commit details

Commits on Apr 30, 2024

  1. Update hashbrown to 0.14

    torokati44 committed Apr 30, 2024
    Copy the full SHA
    d37f049 View commit details
  2. Merge pull request #76 from torokati44/hashbrown-0.14

    Update hashbrown to 0.14
    sile authored Apr 30, 2024
    Copy the full SHA
    27628cb View commit details
  3. Update clap to v4

    sile committed Apr 30, 2024
    Copy the full SHA
    a424630 View commit details
  4. Update Cargo.toml

    sile committed Apr 30, 2024
    Copy the full SHA
    192980e View commit details
  5. Merge pull request #77 from sile/update-clap

    Update clap to v4
    sile authored Apr 30, 2024
    Copy the full SHA
    04565c3 View commit details
  6. Bump version to 2.1.0

    sile committed Apr 30, 2024
    Copy the full SHA
    6676d36 View commit details
55 changes: 40 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ jobs:
strategy:
matrix:
toolchain: [stable, beta, nightly]
features: [--no-default-features, --all-features]
steps:
- name: Checkout sources
uses: actions/checkout@v1
@@ -26,14 +27,49 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: check
args: --all-features --all
args: ${{ matrix.features }} --workspace

no-std:
name: no_std Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v1

- name: Install nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Install cargo no-std-check
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-no-std-check

# https://github.com/mystor/cargo-no-std-check/issues/2
# `--no-default-features` doesn't work with `--workspace` correctly.
- name: Run cargo no-std-check on libflate crate
uses: actions-rs/cargo@v1
with:
command: no-std-check
args: --no-default-features

- name: Run cargo no-std-check on libflate_lz77 crate
uses: actions-rs/cargo@v1
with:
command: no-std-check
args: --no-default-features --manifest-path libflate_lz77/Cargo.toml

test:
name: Test Suite
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: [stable, beta, nightly]
features: [--no-default-features, --all-features]
steps:
- name: Checkout sources
uses: actions/checkout@v1
@@ -49,14 +85,15 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --all-features --all
args: ${{ matrix.features }} --workspace

lints:
name: Lints
runs-on: ubuntu-latest
strategy:
matrix:
toolchain: [stable, beta, nightly]
features: [--no-default-features, --all-features]
steps:
- name: Checkout sources
uses: actions/checkout@v1
@@ -75,21 +112,9 @@ jobs:
command: fmt
args: --all -- --check

- name: Run cargo clippy
if: matrix.toolchain == 'beta'
uses: actions-rs/cargo@v1
with:
command: clippy
# As `return_self_not_must_use` became `pedantic` in the 1.60.0-nightly channel,
# we allow the warning to avoid unnecessary code fixes.
# See: https://github.com/rust-lang/rust-clippy/issues/8197
#
# TODO: Remove this branch once stable-1.59.0 is released.
args: --all-features --all -- -D warnings --allow clippy::return_self_not_must_use

- name: Run cargo clippy
if: matrix.toolchain != 'beta'
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-features --all -- -D warnings
args: ${{ matrix.features }} --workspace -- -D warnings
20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
[package]
name = "libflate"
version = "1.4.0"
version = "2.1.0"
authors = ["Takeru Ohta <phjgt308@gmail.com>"]
description = "A Rust implementation of DEFLATE algorithm and related formats (ZLIB, GZIP)"
homepage = "https://github.com/sile/libflate"
repository = "https://github.com/sile/libflate"
readme = "README.md"
keywords = ["deflate", "gzip", "zlib"]
categories = ["compression"]
categories = ["compression", "no-std"]
license = "MIT"
edition = "2018"
edition = "2021"

[badges]
coveralls = {repository = "sile/libflate"}

[dependencies]
adler32 = "1"
crc32fast = "1.1.1"
libflate_lz77 = { path = "libflate_lz77", version = "1.1", default_features = false }
core2 = { version = "0.4", default_features = false, features = ["alloc"], optional = true }
adler32 = { version = "1", default-features = false }
crc32fast = { version = "1.1.1", default-features = false }
dary_heap = "0.3.5"
libflate_lz77 = { path = "libflate_lz77", version = "2.1.0", default-features = false }
core2 = { version = "0.4", default-features = false, features = ["alloc"] }

[features]
no_std = ["libflate_lz77/no_std", "core2"]
default = ["std"]
std = ["libflate_lz77/std", "core2/std"]

[dev-dependencies]
clap = "2"
clap = { version = "4", features = ["derive"] }

[workspace]
members = ["libflate_lz77"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ Add following lines to your `Cargo.toml`:

```toml
[dependencies]
libflate = "1"
libflate = "2"
```

An Example
184 changes: 82 additions & 102 deletions examples/flate.rs
Original file line number Diff line number Diff line change
@@ -1,68 +1,47 @@
extern crate clap;
extern crate libflate;

#[cfg(not(feature = "no_std"))]
use clap::App;
#[cfg(not(feature = "no_std"))]
use clap::Arg;
#[cfg(not(feature = "no_std"))]
use clap::SubCommand;
#[cfg(not(feature = "no_std"))]
use libflate::gzip;
#[cfg(not(feature = "no_std"))]
use libflate::zlib;
#[cfg(not(feature = "no_std"))]
use std::fs;
#[cfg(not(feature = "no_std"))]
use std::io;
#[cfg(not(feature = "no_std"))]
use std::io::Read;
#[cfg(not(feature = "no_std"))]
use std::io::Write;
#[cfg(not(feature = "no_std"))]
use std::process;

#[cfg(feature = "no_std")]
#[cfg(not(feature = "std"))]
fn main() {}

#[cfg(not(feature = "no_std"))]
#[cfg(feature = "std")]
fn main() {
let matches = App::new("deflate")
.arg(
Arg::with_name("INPUT")
.short("i")
.long("input")
.value_name("FILE")
.takes_value(true)
.default_value("-"),
)
.arg(
Arg::with_name("OUTPUT")
.short("o")
.long("output")
.value_name("FILE")
.takes_value(true)
.default_value("-"),
)
.arg(Arg::with_name("VERBOSE").short("v").long("verbose"))
.subcommand(SubCommand::with_name("copy"))
.subcommand(
SubCommand::with_name("byte-read").arg(
Arg::with_name("UNIT")
.short("u")
.long("unit")
.takes_value(true)
.default_value("1"),
),
)
.subcommand(SubCommand::with_name("gzip-decode"))
.subcommand(SubCommand::with_name("gzip-decode-multi"))
.subcommand(SubCommand::with_name("gzip-encode"))
.subcommand(SubCommand::with_name("zlib-decode"))
.subcommand(SubCommand::with_name("zlib-encode"))
.get_matches();
use clap::Parser;
use libflate::gzip;
use libflate::zlib;
use std::fs;
use std::io;
use std::io::Read;
use std::io::Write;

#[derive(Parser)]
struct Args {
#[clap(short, long, default_value = "-")]
input: String,

#[clap(short, long, default_value = "-")]
output: String,

#[clap(short, long)]
verbose: bool,

#[clap(subcommand)]
command: Command,
}

let input_filename = matches.value_of("INPUT").unwrap();
#[derive(clap::Subcommand)]
enum Command {
Copy,
ByteRead {
#[clap(short, long, default_value = "1")]
unit: usize,
},
GzipDecode,
GzipDecodeMulti,
GzipEncode,
ZlibDecode,
ZlibEncode,
}

let args = Args::parse();
let input_filename = &args.input;
let input: Box<dyn io::Read> = if input_filename == "-" {
Box::new(io::stdin())
} else {
@@ -72,7 +51,7 @@ fn main() {
};
let mut input = io::BufReader::new(input);

let output_filename = matches.value_of("OUTPUT").unwrap();
let output_filename = &args.output;
let output: Box<dyn io::Write> = if output_filename == "-" {
Box::new(io::stdout())
} else if output_filename == "/dev/null" {
@@ -85,49 +64,50 @@ fn main() {
};
let mut output = io::BufWriter::new(output);

let verbose = matches.is_present("VERBOSE");
if let Some(_matches) = matches.subcommand_matches("copy") {
io::copy(&mut input, &mut output).expect("Coyping failed");
} else if let Some(matches) = matches.subcommand_matches("byte-read") {
let unit = matches
.value_of("UNIT")
.and_then(|x| x.parse::<usize>().ok())
.unwrap();
let mut buf = vec![0; unit];
let mut reader = input;
let mut count = 0;
while let Ok(size) = reader.read(&mut buf) {
if size == 0 {
break;
let verbose = args.verbose;
match args.command {
Command::Copy => {
io::copy(&mut input, &mut output).expect("Coyping failed");
}
Command::ByteRead { unit } => {
let mut buf = vec![0; unit];
let mut reader = input;
let mut count = 0;
while let Ok(size) = reader.read(&mut buf) {
if size == 0 {
break;
}
count += size;
}
count += size;
println!("COUNT: {}", count);
}
println!("COUNT: {}", count);
} else if let Some(_matches) = matches.subcommand_matches("gzip-decode") {
let mut decoder = gzip::Decoder::new(input).expect("Read GZIP header failed");
if verbose {
let _ = writeln!(&mut io::stderr(), "HEADER: {:?}", decoder.header());
Command::GzipDecode => {
let mut decoder = gzip::Decoder::new(input).expect("Read GZIP header failed");
if verbose {
let _ = writeln!(&mut io::stderr(), "HEADER: {:?}", decoder.header());
}
io::copy(&mut decoder, &mut output).expect("Decoding GZIP stream failed");
}
io::copy(&mut decoder, &mut output).expect("Decoding GZIP stream failed");
} else if let Some(_matches) = matches.subcommand_matches("gzip-decode-multi") {
let mut decoder = gzip::MultiDecoder::new(input).expect("Read GZIP header failed");
io::copy(&mut decoder, &mut output).expect("Decoding GZIP stream failed");
} else if let Some(_matches) = matches.subcommand_matches("gzip-encode") {
let mut encoder = gzip::Encoder::new(output).unwrap();
io::copy(&mut input, &mut encoder).expect("Encoding GZIP stream failed");
encoder.finish().into_result().unwrap();
} else if let Some(_matches) = matches.subcommand_matches("zlib-decode") {
let mut decoder = zlib::Decoder::new(input).expect("Read ZLIB header failed");
if verbose {
let _ = writeln!(&mut io::stderr(), "HEADER: {:?}", decoder.header());
Command::GzipDecodeMulti => {
let mut decoder = gzip::MultiDecoder::new(input).expect("Read GZIP header failed");
io::copy(&mut decoder, &mut output).expect("Decoding GZIP stream failed");
}
Command::GzipEncode => {
let mut encoder = gzip::Encoder::new(output).unwrap();
io::copy(&mut input, &mut encoder).expect("Encoding GZIP stream failed");
encoder.finish().into_result().unwrap();
}
Command::ZlibDecode => {
let mut decoder = zlib::Decoder::new(input).expect("Read ZLIB header failed");
if verbose {
let _ = writeln!(&mut io::stderr(), "HEADER: {:?}", decoder.header());
}
io::copy(&mut decoder, &mut output).expect("Decoding ZLIB stream failed");
}
Command::ZlibEncode => {
let mut encoder = zlib::Encoder::new(output).unwrap();
io::copy(&mut input, &mut encoder).expect("Encoding ZLIB stream failed");
encoder.finish().into_result().unwrap();
}
io::copy(&mut decoder, &mut output).expect("Decoding ZLIB stream failed");
} else if let Some(_matches) = matches.subcommand_matches("zlib-encode") {
let mut encoder = zlib::Encoder::new(output).unwrap();
io::copy(&mut input, &mut encoder).expect("Encoding ZLIB stream failed");
encoder.finish().into_result().unwrap();
} else {
println!("{}", matches.usage());
process::exit(1);
}
}
3 changes: 2 additions & 1 deletion flate_bench/Cargo.toml
Original file line number Diff line number Diff line change
@@ -2,9 +2,10 @@
name = "flate_bench"
version = "0.1.0"
authors = ["Takeru Ohta <phjgt308@gmail.com>"]
edition = "2021"

[dependencies]
clap = "*"
clap = { version = "4", features = ["derive"] }
flate2 = "*"
inflate = "*"
libflate = {path = "../"}
Loading