Skip to content

Commit

Permalink
Documentation links
Browse files Browse the repository at this point in the history
  • Loading branch information
opilar committed Apr 19, 2017
1 parent 4eefbc0 commit 882bcf1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 36 deletions.
8 changes: 6 additions & 2 deletions src/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ use libc;

use ffi;

/// The CRC calculated by a CrcReader.
/// The CRC calculated by a [`CrcReader`].
///
/// [`CrcReader`]: struct.CrcReader.html
pub struct Crc {
crc: libc::c_ulong,
amt: u32,
}

/// A wrapper around a `std::io::Read` that calculates the CRC.
/// A wrapper around a [`Read`] that calculates the CRC.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct CrcReader<R> {
inner: R,
crc: Crc,
Expand Down
24 changes: 18 additions & 6 deletions src/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,62 @@ use {Compress, Decompress};

/// A DEFLATE encoder, or compressor.
///
/// This structure implements a `Write` interface and takes a stream of
/// This structure implements a [`Write`] interface and takes a stream of
/// uncompressed data, writing the compressed data to the wrapped writer.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
}

/// A DEFLATE encoder, or compressor.
///
/// This structure implements a `Read` interface and will read uncompressed
/// This structure implements a [`Read`] interface and will read uncompressed
/// data from an underlying stream and emit a stream of compressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct EncoderReader<R: Read> {
inner: EncoderReaderBuf<BufReader<R>>,
}

/// A DEFLATE encoder, or compressor.
///
/// This structure implements a `BufRead` interface and will read uncompressed
/// This structure implements a [`BufRead`] interface and will read uncompressed
/// data from an underlying stream and emit a stream of compressed data.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
pub struct EncoderReaderBuf<R: BufRead> {
obj: R,
data: Compress,
}

/// A DEFLATE decoder, or decompressor.
///
/// This structure implements a `Read` interface and takes a stream of
/// This structure implements a [`Read`] interface and takes a stream of
/// compressed data as input, providing the decompressed data when read from.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct DecoderReader<R: Read> {
inner: DecoderReaderBuf<BufReader<R>>,
}

/// A DEFLATE decoder, or decompressor.
///
/// This structure implements a `BufRead` interface and takes a stream of
/// This structure implements a [`BufRead`] interface and takes a stream of
/// compressed data as input, providing the decompressed data when read from.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
pub struct DecoderReaderBuf<R: BufRead> {
obj: R,
data: Decompress,
}

/// A DEFLATE decoder, or decompressor.
///
/// This structure implements a `Write` and will emit a stream of decompressed
/// This structure implements a [`Write`] and will emit a stream of decompressed
/// data when fed a stream of compressed data.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct DecoderWriter<W: Write> {
inner: zio::Writer<W, Decompress>,
}
Expand Down
32 changes: 23 additions & 9 deletions src/gz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ static FCOMMENT: u8 = 1 << 4;

/// A gzip streaming encoder
///
/// This structure exposes a `Write` interface that will emit compressed data
/// This structure exposes a [`Write`] interface that will emit compressed data
/// to the underlying writer `W`.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
crc: Crc,
Expand All @@ -39,18 +41,22 @@ pub struct EncoderWriter<W: Write> {

/// A gzip streaming encoder
///
/// This structure exposes a `Read` interface that will read uncompressed data
/// from the underlying reader and expose the compressed version as a `Read`
/// This structure exposes a [`Read`] interface that will read uncompressed data
/// from the underlying reader and expose the compressed version as a [`Read`]
/// interface.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct EncoderReader<R: Read> {
inner: EncoderReaderBuf<BufReader<R>>,
}

/// A gzip streaming encoder
///
/// This structure exposes a `Read` interface that will read uncompressed data
/// from the underlying reader and expose the compressed version as a `Read`
/// This structure exposes a [`Read`] interface that will read uncompressed data
/// from the underlying reader and expose the compressed version as a [`Read`]
/// interface.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct EncoderReaderBuf<R: BufRead> {
inner: deflate::EncoderReaderBuf<CrcReader<R>>,
header: Vec<u8>,
Expand All @@ -70,8 +76,10 @@ pub struct Builder {

/// A gzip streaming decoder
///
/// This structure exposes a `Read` interface that will consume compressed
/// This structure exposes a [`Read`] interface that will consume compressed
/// data from the underlying reader and emit uncompressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct DecoderReader<R: Read> {
inner: DecoderReaderBuf<BufReader<R>>,
}
Expand All @@ -85,16 +93,20 @@ pub struct DecoderReader<R: Read> {
/// first gzip member. The multistream format is commonly used in bioinformatics,
/// for example when using the BGZF compressed data.
///
/// This structure exposes a `Read` interface that will consume all gzip members
/// This structure exposes a [`Read`] interface that will consume all gzip members
/// from the underlying reader and emit uncompressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct MultiDecoderReader<R: Read> {
inner: MultiDecoderReaderBuf<BufReader<R>>,
}

/// A gzip streaming decoder
///
/// This structure exposes a `Read` interface that will consume compressed
/// This structure exposes a [`Read`] interface that will consume compressed
/// data from the underlying reader and emit uncompressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct DecoderReaderBuf<R: BufRead> {
inner: CrcReader<deflate::DecoderReaderBuf<R>>,
header: Header,
Expand All @@ -110,8 +122,10 @@ pub struct DecoderReaderBuf<R: BufRead> {
/// the first gzip member. The multistream format is commonly used in
/// bioinformatics, for example when using the BGZF compressed data.
///
/// This structure exposes a `Read` interface that will consume all gzip members
/// This structure exposes a [`Read`] interface that will consume all gzip members
/// from the underlying reader and emit uncompressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct MultiDecoderReaderBuf<R: BufRead> {
inner: CrcReader<deflate::DecoderReaderBuf<R>>,
header: Header,
Expand Down
41 changes: 30 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,52 @@
//! libflate library by providing a streaming encoder/decoder rather than purely
//! an in-memory encoder/decoder.
//!
//! Like with libflate, flate2 is based on [`miniz.c`][1]
//! Like with [`libflate`], flate2 is based on [`miniz.c`][1]
//!
//! [1]: https://code.google.com/p/miniz/
//! [`libflate`]: https://docs.rs/crate/libflate/
//!
//! # Organization
//!
//! This crate consists mainly of two modules, `read` and `write`. Each
//! This crate consists mainly of two modules, [`read`] and [`write`]. Each
//! module contains a number of types used to encode and decode various streams
//! of data. All types in the `write` module work on instances of `Write`,
//! whereas all types in the `read` module work on instances of `Read`.
//! of data. All types in the [`write`] module work on instances of [`Write`],
//! whereas all types in the [`read`] module work on instances of [`Read`].
//!
//! Other various types are provided at the top-level of the crate for
//! management and dealing with encoders/decoders.
//!
//! [`read`]: read/index.html
//! [`write`]: write/index.html
//! [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
//! [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
//!
//! # Helper traits
//!
//! There are two helper traits provided: `FlateReader` and `FlateWriter`.
//! There are two helper traits provided: [`FlateReadExt`] and [`FlateWriteExt`].
//! These provide convenience methods for creating a decoder/encoder out of an
//! already existing stream to chain construction.
//!
//! [`FlateReadExt`]: trait.FlateReadExt.html
//! [`FlateWriteExt`]: trait.FlateWriteExt.html
//!
//! # Async I/O
//!
//! This crate optionally can support async I/O streams with the Tokio stack via
//! This crate optionally can support async I/O streams with the [Tokio stack] via
//! the `tokio` feature of this crate:
//!
//! [Tokio stack]: https://tokio.rs/
//!
//! ```toml
//! flate2 = { version = "0.2", features = ["tokio"] }
//! ```
//!
//! All methods are internally capable of working with streams that may return
//! `ErrorKind::WouldBlock` when they're not ready to perform the particular
//! [`ErrorKind::WouldBlock`] when they're not ready to perform the particular
//! operation.
//!
//! [`ErrorKind::WouldBlock`]: https://doc.rust-lang.org/std/io/enum.ErrorKind.html
//!
//! Note that care needs to be taken when using these objects, however. The
//! Tokio runtime, in particular, requires that data is fully flushed before
//! dropping streams. For compatibility with blocking streams all streams are
Expand Down Expand Up @@ -77,8 +90,10 @@ mod zio;
mod mem;
mod zlib;

/// Types which operate over `Read` streams, both encoders and decoders for
/// Types which operate over [`Read`] streams, both encoders and decoders for
/// various formats.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub mod read {
pub use deflate::EncoderReader as DeflateEncoder;
pub use deflate::DecoderReader as DeflateDecoder;
Expand All @@ -89,8 +104,10 @@ pub mod read {
pub use gz::MultiDecoderReader as MultiGzDecoder;
}

/// Types which operate over `Write` streams, both encoders and decoders for
/// Types which operate over [`Write`] streams, both encoders and decoders for
/// various formats.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
pub mod write {
pub use deflate::EncoderWriter as DeflateEncoder;
pub use deflate::DecoderWriter as DeflateDecoder;
Expand All @@ -99,8 +116,10 @@ pub mod write {
pub use gz::EncoderWriter as GzEncoder;
}

/// Types which operate over `BufRead` streams, both encoders and decoders for
/// Types which operate over [`BufRead`] streams, both encoders and decoders for
/// various formats.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
pub mod bufread {
pub use deflate::EncoderReaderBuf as DeflateEncoder;
pub use deflate::DecoderReaderBuf as DeflateDecoder;
Expand Down Expand Up @@ -143,7 +162,7 @@ pub enum Compression {
Default = 6,
}

///Default to Compression::Default.
/// Default to Compression::Default.
impl Default for Compression {
fn default() -> Compression {
Compression::Default
Expand Down
10 changes: 8 additions & 2 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,31 @@ use ffi;
/// Raw in-memory compression stream for blocks of data.
///
/// This type is the building block for the I/O streams in the rest of this
/// crate. It requires more management than the `Read`/`Write` API but is
/// crate. It requires more management than the [`Read`]/[`Write`] API but is
/// maximally flexible in terms of accepting input from any source and being
/// able to produce output to any memory location.
///
/// It is recommended to use the I/O stream adaptors over this type as they're
/// easier to use.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
pub struct Compress {
inner: Stream<DirCompress>,
}

/// Raw in-memory decompression stream for blocks of data.
///
/// This type is the building block for the I/O streams in the rest of this
/// crate. It requires more management than the `Read`/`Write` API but is
/// crate. It requires more management than the [`Read`]/[`Write`] API but is
/// maximally flexible in terms of accepting input from any source and being
/// able to produce output to any memory location.
///
/// It is recommended to use the I/O stream adaptors over this type as they're
/// easier to use.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
pub struct Decompress {
inner: Stream<DirDecompress>,
}
Expand Down
24 changes: 18 additions & 6 deletions src/zlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,62 @@ use {Compress, Decompress};

/// A ZLIB encoder, or compressor.
///
/// This structure implements a `Write` interface and takes a stream of
/// This structure implements a [`Write`] interface and takes a stream of
/// uncompressed data, writing the compressed data to the wrapped writer.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
pub struct EncoderWriter<W: Write> {
inner: zio::Writer<W, Compress>,
}

/// A ZLIB encoder, or compressor.
///
/// This structure implements a `Read` interface and will read uncompressed
/// This structure implements a [`Read`] interface and will read uncompressed
/// data from an underlying stream and emit a stream of compressed data.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct EncoderReader<R> {
inner: EncoderReaderBuf<BufReader<R>>,
}

/// A ZLIB encoder, or compressor.
///
/// This structure implements a `BufRead` interface and will read uncompressed
/// This structure implements a [`BufRead`] interface and will read uncompressed
/// data from an underlying stream and emit a stream of compressed data.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
pub struct EncoderReaderBuf<R> {
obj: R,
data: Compress,
}

/// A ZLIB decoder, or decompressor.
///
/// This structure implements a `Read` interface and takes a stream of
/// This structure implements a [`Read`] interface and takes a stream of
/// compressed data as input, providing the decompressed data when read from.
///
/// [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html
pub struct DecoderReader<R> {
inner: DecoderReaderBuf<BufReader<R>>,
}

/// A ZLIB decoder, or decompressor.
///
/// This structure implements a `BufRead` interface and takes a stream of
/// This structure implements a [`BufRead`] interface and takes a stream of
/// compressed data as input, providing the decompressed data when read from.
///
/// [`BufRead`]: https://doc.rust-lang.org/std/io/trait.BufRead.html
pub struct DecoderReaderBuf<R> {
obj: R,
data: Decompress,
}

/// A ZLIB decoder, or decompressor.
///
/// This structure implements a `Write` and will emit a stream of decompressed
/// This structure implements a [`Write`] and will emit a stream of decompressed
/// data when fed a stream of compressed data.
///
/// [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html
pub struct DecoderWriter<W: Write> {
inner: zio::Writer<W, Decompress>,
}
Expand Down

0 comments on commit 882bcf1

Please sign in to comment.