Skip to content

Commit

Permalink
Merge branch 'master' of /~https://github.com/kper/flate2-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Apr 20, 2017
2 parents 878fa94 + 3012817 commit 2af7098
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/bufreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ pub struct BufReader<R> {
cap: usize,
}

impl<R> ::std::fmt::Debug for BufReader<R> where R: ::std::fmt::Debug {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error>{
fmt.debug_struct("BufReader")
.field("reader", &self.inner)
.field("buffer", &format_args!("{}/{}", self.cap - self.pos, self.buf.len()))
.finish()
}
}

impl<R: Read> BufReader<R> {
pub fn new(inner: R) -> BufReader<R> {
BufReader::with_buf(vec![0; 32 * 1024], inner)
Expand Down
2 changes: 2 additions & 0 deletions src/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use ffi;
/// The CRC calculated by a [`CrcReader`].
///
/// [`CrcReader`]: struct.CrcReader.html
#[derive(Debug)]
pub struct Crc {
crc: libc::c_ulong,
amt: u32,
Expand All @@ -17,6 +18,7 @@ pub struct Crc {
/// A wrapper around a [`Read`] that calculates the CRC.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct CrcReader<R> {
inner: R,
crc: Crc,
Expand Down
6 changes: 6 additions & 0 deletions src/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use {Compress, Decompress};
/// uncompressed data, writing the compressed data to the wrapped writer.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
#[derive(Debug)]
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
}
Expand All @@ -29,6 +30,7 @@ pub struct EncoderWriter<W: Write> {
/// data from an underlying stream and emit a stream of compressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct EncoderReader<R> {
inner: EncoderReaderBuf<BufReader<R>>,
}
Expand All @@ -39,6 +41,7 @@ pub struct EncoderReader<R> {
/// data from an underlying stream and emit a stream of compressed data.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
#[derive(Debug)]
pub struct EncoderReaderBuf<R> {
obj: R,
data: Compress,
Expand All @@ -50,6 +53,7 @@ pub struct EncoderReaderBuf<R> {
/// compressed data as input, providing the decompressed data when read from.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct DecoderReader<R> {
inner: DecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -60,6 +64,7 @@ pub struct DecoderReader<R> {
/// compressed data as input, providing the decompressed data when read from.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
#[derive(Debug)]
pub struct DecoderReaderBuf<R> {
obj: R,
data: Decompress,
Expand All @@ -71,6 +76,7 @@ pub struct DecoderReaderBuf<R> {
/// data when fed a stream of compressed data.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct DecoderWriter<W: Write> {
inner: zio::Writer<W, Decompress>,
}
Expand Down
12 changes: 12 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ mod imp {
inner: Box<mz_stream>,
}

impl ::std::fmt::Debug for StreamWrapper{
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error>{
write!(f, "StreamWrapper")
}
}

impl Default for StreamWrapper {
fn default() -> StreamWrapper {
StreamWrapper {
Expand Down Expand Up @@ -105,6 +111,12 @@ mod imp {
inner: mz_stream,
}

impl ::std::fmt::Debug for StreamWrapper{
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error>{
write!(f, "StreamWrapper")
}
}

impl Default for StreamWrapper {
fn default() -> StreamWrapper {
StreamWrapper {
Expand Down
10 changes: 9 additions & 1 deletion src/gz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static FCOMMENT: u8 = 1 << 4;
/// to the underlying writer `W`.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
#[derive(Debug)]
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
crc: Crc,
Expand All @@ -46,6 +47,7 @@ pub struct EncoderWriter<W: Write> {
/// interface.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct EncoderReader<R> {
inner: EncoderReaderBuf<BufReader<R>>,
}
Expand All @@ -57,6 +59,7 @@ pub struct EncoderReader<R> {
/// interface.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct EncoderReaderBuf<R> {
inner: deflate::EncoderReaderBuf<CrcReader<R>>,
header: Vec<u8>,
Expand All @@ -67,6 +70,7 @@ pub struct EncoderReaderBuf<R> {
/// A builder structure to create a new gzip Encoder.
///
/// This structure controls header configuration options such as the filename.
#[derive(Debug)]
pub struct Builder {
extra: Option<Vec<u8>>,
filename: Option<CString>,
Expand All @@ -80,6 +84,7 @@ pub struct Builder {
/// data from the underlying reader and emit uncompressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct DecoderReader<R> {
inner: DecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -97,6 +102,7 @@ pub struct DecoderReader<R> {
/// from the underlying reader and emit uncompressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct MultiDecoderReader<R> {
inner: MultiDecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -107,6 +113,7 @@ pub struct MultiDecoderReader<R> {
/// data from the underlying reader and emit uncompressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct DecoderReaderBuf<R> {
inner: CrcReader<deflate::DecoderReaderBuf<R>>,
header: Header,
Expand All @@ -126,6 +133,7 @@ pub struct DecoderReaderBuf<R> {
/// from the underlying reader and emit uncompressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct MultiDecoderReaderBuf<R> {
inner: CrcReader<deflate::DecoderReaderBuf<R>>,
header: Header,
Expand All @@ -136,7 +144,7 @@ pub struct MultiDecoderReaderBuf<R> {
///
/// The header can contain metadata about the file that was compressed, if
/// present.
#[derive(PartialEq)]
#[derive(PartialEq, Debug)]
pub struct Header {
extra: Option<Vec<u8>>,
filename: Option<Vec<u8>>,
Expand Down
9 changes: 7 additions & 2 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use ffi;
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
#[derive(Debug)]
pub struct Compress {
inner: Stream<DirCompress>,
}
Expand All @@ -37,10 +38,12 @@ pub struct Compress {
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
#[derive(Debug)]
pub struct Decompress {
inner: Stream<DirDecompress>,
}

#[derive(Debug)]
struct Stream<D: Direction> {
stream_wrapper: ffi::StreamWrapper,
total_in: u64,
Expand All @@ -55,12 +58,14 @@ trait Direction {
unsafe fn destroy(stream: *mut ffi::mz_stream) -> c_int;
}

#[derive(Debug)]
enum DirCompress {}
#[derive(Debug)]
enum DirDecompress {}

/// Values which indicate the form of flushing to be used when compressing or
/// decompressing in-memory data.
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Flush {
/// A typical parameter for passing to compression/decompression functions,
/// this indicates that the underlying stream to decide how much data to
Expand Down Expand Up @@ -119,7 +124,7 @@ pub struct DataError(());

/// Possible status results of compressing some data or successfully
/// decompressing a block of data.
#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Status {
/// Indicates success.
///
Expand Down
1 change: 1 addition & 0 deletions src/zio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::mem;

use {Decompress, Compress, Status, Flush, DataError};

#[derive(Debug)]
pub struct Writer<W: Write, D: Ops> {
obj: Option<W>,
pub data: D,
Expand Down
6 changes: 6 additions & 0 deletions src/zlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use {Compress, Decompress};
/// uncompressed data, writing the compressed data to the wrapped writer.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
#[derive(Debug)]
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
}
Expand All @@ -29,6 +30,7 @@ pub struct EncoderWriter<W: Write> {
/// data from an underlying stream and emit a stream of compressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct EncoderReader<R> {
inner: EncoderReaderBuf<BufReader<R>>,
}
Expand All @@ -39,6 +41,7 @@ pub struct EncoderReader<R> {
/// data from an underlying stream and emit a stream of compressed data.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
#[derive(Debug)]
pub struct EncoderReaderBuf<R> {
obj: R,
data: Compress,
Expand All @@ -50,6 +53,7 @@ pub struct EncoderReaderBuf<R> {
/// compressed data as input, providing the decompressed data when read from.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
#[derive(Debug)]
pub struct DecoderReader<R> {
inner: DecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -60,6 +64,7 @@ pub struct DecoderReader<R> {
/// compressed data as input, providing the decompressed data when read from.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
#[derive(Debug)]
pub struct DecoderReaderBuf<R> {
obj: R,
data: Decompress,
Expand All @@ -71,6 +76,7 @@ pub struct DecoderReaderBuf<R> {
/// data when fed a stream of compressed data.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
#[derive(Debug)]
pub struct DecoderWriter<W: Write> {
inner: zio::Writer<W, Decompress>,
}
Expand Down

0 comments on commit 2af7098

Please sign in to comment.