Sha256: 0d260cbe62f4eaecaa0f6f825dd565351dfc50df70e99166c826b414a94f51bd

Contents?: true

Size: 1.49 KB

Versions: 37

Compression:

Stored size: 1.49 KB

Contents

use std::io;

use super::{Decoder, Encoder};

/// Decompress from the given source as if using a `Decoder`.
///
/// The input data must be in the zstd frame format.
pub fn decode_all<R: io::Read>(source: R) -> io::Result<Vec<u8>> {
    let mut result = Vec::new();
    copy_decode(source, &mut result)?;
    Ok(result)
}

/// Decompress from the given source as if using a `Decoder`.
///
/// Decompressed data will be appended to `destination`.
pub fn copy_decode<R, W>(source: R, mut destination: W) -> io::Result<()>
where
    R: io::Read,
    W: io::Write,
{
    let mut decoder = Decoder::new(source)?;
    io::copy(&mut decoder, &mut destination)?;
    Ok(())
}

/// Compress all data from the given source as if using an `Encoder`.
///
/// Result will be in the zstd frame format.
///
/// A level of `0` uses zstd's default (currently `3`).
pub fn encode_all<R: io::Read>(source: R, level: i32) -> io::Result<Vec<u8>> {
    let mut result = Vec::<u8>::new();
    copy_encode(source, &mut result, level)?;
    Ok(result)
}

/// Compress all data from the given source as if using an `Encoder`.
///
/// Compressed data will be appended to `destination`.
///
/// A level of `0` uses zstd's default (currently `3`).
pub fn copy_encode<R, W>(
    mut source: R,
    destination: W,
    level: i32,
) -> io::Result<()>
where
    R: io::Read,
    W: io::Write,
{
    let mut encoder = Encoder::new(destination, level)?;
    io::copy(&mut source, &mut encoder)?;
    encoder.finish()?;
    Ok(())
}

#[cfg(tests)]
mod tests {}

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
wasmtime-28.0.0 ./ext/cargo-vendor/zstd-0.13.2/src/stream/functions.rs
wasmtime-27.0.0 ./ext/cargo-vendor/zstd-0.13.2/src/stream/functions.rs
wasmtime-26.0.0 ./ext/cargo-vendor/zstd-0.13.2/src/stream/functions.rs
wasmtime-25.0.2 ./ext/cargo-vendor/zstd-0.13.2/src/stream/functions.rs
wasmtime-25.0.1 ./ext/cargo-vendor/zstd-0.13.2/src/stream/functions.rs
wasmtime-25.0.0 ./ext/cargo-vendor/zstd-0.13.2/src/stream/functions.rs
wasmtime-24.0.0 ./ext/cargo-vendor/zstd-0.13.2/src/stream/functions.rs
wasmtime-23.0.2 ./ext/cargo-vendor/zstd-0.13.1/src/stream/functions.rs
wasmtime-22.0.0 ./ext/cargo-vendor/zstd-0.13.1/src/stream/functions.rs
wasmtime-21.0.1 ./ext/cargo-vendor/zstd-0.13.1/src/stream/functions.rs
wasmtime-20.0.2 ./ext/cargo-vendor/zstd-0.13.1/src/stream/functions.rs
wasmtime-20.0.0 ./ext/cargo-vendor/zstd-0.13.1/src/stream/functions.rs
wasmtime-18.0.3 ./ext/cargo-vendor/zstd-0.11.2+zstd.1.5.2/src/stream/functions.rs
wasmtime-17.0.1 ./ext/cargo-vendor/zstd-0.11.2+zstd.1.5.2/src/stream/functions.rs
wasmtime-17.0.0 ./ext/cargo-vendor/zstd-0.11.2+zstd.1.5.2/src/stream/functions.rs
wasmtime-16.0.0 ./ext/cargo-vendor/zstd-0.11.2+zstd.1.5.2/src/stream/functions.rs
wasmtime-15.0.1 ./ext/cargo-vendor/zstd-0.11.2+zstd.1.5.2/src/stream/functions.rs
wasmtime-15.0.0 ./ext/cargo-vendor/zstd-0.11.2+zstd.1.5.2/src/stream/functions.rs
wasmtime-14.0.4 ./ext/cargo-vendor/zstd-0.11.2+zstd.1.5.2/src/stream/functions.rs
wasmtime-14.0.3 ./ext/cargo-vendor/zstd-0.11.2+zstd.1.5.2/src/stream/functions.rs