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: Nullus157/async-compression
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.4.21
Choose a base ref
...
head repository: Nullus157/async-compression
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.4.22
Choose a head ref
  • 15 commits
  • 18 files changed
  • 5 contributors

Commits on Mar 15, 2025

  1. Merge pull request #334 from Nullus157/release-plz-2025-03-14T09-41-05Z

    chore: release v0.4.21
    robjtede authored Mar 15, 2025
    Copy the full SHA
    beb5c6b View commit details

Commits on Mar 16, 2025

  1. feat: add lz4 support

    arpankapoor committed Mar 16, 2025
    Copy the full SHA
    8f00dab View commit details
  2. chore: fmt

    arpankapoor committed Mar 16, 2025
    Copy the full SHA
    5191039 View commit details
  3. Copy the full SHA
    394426f View commit details
  4. style change for min

    arpankapoor committed Mar 16, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ba9c98a View commit details
  5. refactor: rewrite encoder to minimize internal buffer usage

    arpankapoor committed Mar 16, 2025
    Copy the full SHA
    1aba65b View commit details
  6. refactor: drain buffer inside write

    arpankapoor committed Mar 16, 2025
    Copy the full SHA
    9e3774f View commit details

Commits on Mar 19, 2025

  1. refactor: avoid unwrap_unchecked

    arpankapoor committed Mar 19, 2025
    Copy the full SHA
    e189f86 View commit details

Commits on Mar 22, 2025

  1. refactor: calculate src size just once

    arpankapoor committed Mar 22, 2025
    Copy the full SHA
    2060bb7 View commit details
  2. refactor: use actual dst size instead of min_dst_size

    arpankapoor committed Mar 22, 2025
    Copy the full SHA
    49375b4 View commit details

Commits on Mar 24, 2025

  1. Expose total_in/total_out in DeflateEncoder

    ardurin committed Mar 24, 2025
    Copy the full SHA
    a45581e View commit details

Commits on Mar 25, 2025

  1. Merge pull request #331 from arpankapoor/lz4

    feat: add lz4 support
    NobodyXu authored Mar 25, 2025
    Copy the full SHA
    ca9cd30 View commit details
  2. Merge pull request #337 from ardurin/main

    Expose total_in/total_out in DeflateEncoder
    NobodyXu authored Mar 25, 2025
    Copy the full SHA
    0ed8747 View commit details
  3. chore: release v0.4.22

    github-actions[bot] authored Mar 25, 2025
    Copy the full SHA
    7a33560 View commit details
  4. Update CHANGELOG.md

    Signed-off-by: Jiahao XU <30436523+NobodyXu@users.noreply.github.com>
    NobodyXu authored Mar 25, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6657e67 View commit details
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0),

## Unreleased

## [0.4.22](https://github.com/Nullus157/async-compression/compare/v0.4.21...v0.4.22) - 2025-03-25

### Other

- Add lz4 encoder/decoder
- Expose total_in/total_out in DeflateEncoder

## [0.4.21](https://github.com/Nullus157/async-compression/compare/v0.4.20...v0.4.21) - 2025-03-15

### Fixed
10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "async-compression"
version = "0.4.21"
version = "0.4.22"
authors = ["Wim Looman <wim@nemo157.com>", "Allen Bui <fairingrey@gmail.com>"]
edition = "2018"
resolver = "2"
@@ -20,11 +20,12 @@ rustdoc-args = ["--cfg", "docsrs"]
# groups
all = ["all-implementations", "all-algorithms"]
all-implementations = ["futures-io", "tokio"]
all-algorithms = ["brotli", "bzip2", "deflate", "gzip", "lzma", "xz", "zlib", "zstd", "deflate64"]
all-algorithms = ["brotli", "bzip2", "deflate", "gzip", "lz4", "lzma", "xz", "zlib", "zstd", "deflate64"]

# algorithms
deflate = ["flate2"]
gzip = ["flate2"]
lz4 = ["dep:lz4"]
lzma = ["dep:liblzma"]
xz = ["lzma"]
xz2 = ["xz"]
@@ -40,6 +41,7 @@ flate2 = { version = "1.0.13", optional = true }
futures-core = { version = "0.3", default-features = false }
futures-io = { version = "0.3", default-features = false, features = ["std"], optional = true }
libzstd = { package = "zstd", version = "0.13.1", optional = true, default-features = false }
lz4 = { version = "1.28.1", optional = true }
memchr = "2"
pin-project-lite = "0.2"
tokio = { version = "1.24.2", optional = true, default-features = false }
@@ -74,6 +76,10 @@ required-features = ["deflate"]
name = "gzip"
required-features = ["gzip"]

[[test]]
name = "lz4"
required-features = ["lz4"]

[[test]]
name = "lzma"
required-features = ["lzma"]
4 changes: 4 additions & 0 deletions src/codec/deflate/encoder.rs
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@ impl DeflateEncoder {
inner: crate::codec::FlateEncoder::new(level, false),
}
}

pub(crate) fn get_ref(&self) -> &crate::codec::FlateEncoder {
&self.inner
}
}

impl Encode for DeflateEncoder {
93 changes: 93 additions & 0 deletions src/codec/lz4/decoder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use std::io::Result;

use lz4::liblz4::{
check_error, LZ4FDecompressionContext, LZ4F_createDecompressionContext, LZ4F_decompress,
LZ4F_freeDecompressionContext, LZ4F_resetDecompressionContext, LZ4F_VERSION,
};

use crate::{codec::Decode, unshared::Unshared, util::PartialBuffer};

#[derive(Debug)]
struct DecoderContext {
ctx: LZ4FDecompressionContext,
}

#[derive(Debug)]
pub struct Lz4Decoder {
ctx: Unshared<DecoderContext>,
}

impl DecoderContext {
fn new() -> Result<Self> {
let mut context = LZ4FDecompressionContext(core::ptr::null_mut());
check_error(unsafe { LZ4F_createDecompressionContext(&mut context, LZ4F_VERSION) })?;
Ok(Self { ctx: context })
}
}

impl Drop for DecoderContext {
fn drop(&mut self) {
unsafe { LZ4F_freeDecompressionContext(self.ctx) };
}
}

impl Lz4Decoder {
pub(crate) fn new() -> Self {
Self {
ctx: Unshared::new(DecoderContext::new().unwrap()),
}
}
}

impl Decode for Lz4Decoder {
fn reinit(&mut self) -> Result<()> {
unsafe { LZ4F_resetDecompressionContext(self.ctx.get_mut().ctx) };
Ok(())
}

fn decode(
&mut self,
input: &mut PartialBuffer<impl AsRef<[u8]>>,
output: &mut PartialBuffer<impl AsRef<[u8]> + AsMut<[u8]>>,
) -> Result<bool> {
let mut output_size = output.unwritten().len();
let mut input_size = input.unwritten().len();
let remaining = unsafe {
check_error(LZ4F_decompress(
self.ctx.get_mut().ctx,
output.unwritten_mut().as_mut_ptr(),
&mut output_size,
input.unwritten().as_ptr(),
&mut input_size,
core::ptr::null(),
))?
};
input.advance(input_size);
output.advance(output_size);
Ok(remaining == 0)
}

fn flush(
&mut self,
output: &mut PartialBuffer<impl AsRef<[u8]> + AsMut<[u8]>>,
) -> Result<bool> {
self.decode(&mut PartialBuffer::new(&[][..]), output)?;

loop {
let old_len = output.written().len();
self.decode(&mut PartialBuffer::new(&[][..]), output)?;
if output.written().len() == old_len {
break;
}
}

Ok(!output.unwritten().is_empty())
}

fn finish(
&mut self,
output: &mut PartialBuffer<impl AsRef<[u8]> + AsMut<[u8]>>,
) -> Result<bool> {
self.flush(output)
}
}
Loading