Skip to content

Commit

Permalink
Merge pull request #43 from image-rs/doc-spelling
Browse files Browse the repository at this point in the history
Fix various spelling errors and details
  • Loading branch information
HeroicKatora authored Jan 27, 2020
2 parents 8640a15 + 72bde6f commit 2385f2a
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 80 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
[![Build Status](https://travis-ci.org/image-rs/deflate-rs.svg)](https://travis-ci.org/image-rs/deflate-rs)[![Crates.io](https://img.shields.io/crates/v/deflate.svg)](https://crates.io/crates/deflate)[![Docs](https://docs.rs/deflate/badge.svg)](https://docs.rs/deflate)


An implementation of a [DEFLATE](http://www.gzip.org/zlib/rfc-deflate.html) encoder in pure rust. Not a direct port, but does take some inspiration from [zlib](http://www.zlib.net/), [miniz](https://github.com/richgel999/miniz) and [zopfli](https://github.com/google/zopfli). The API is based on the one in the [flate2](https://crates.io/crates/flate2) crate that contains bindings, zlib miniz_oxide, and miniz.
An implementation of a [DEFLATE](http://www.gzip.org/zlib/rfc-deflate.html) encoder in pure Rust. Not a direct port, but does take some inspiration from [zlib](http://www.zlib.net/), [miniz](https://github.com/richgel999/miniz) and [zopfli](https://github.com/google/zopfli). The API is based on the one in the [flate2](https://crates.io/crates/flate2) crate that contains bindings, zlib miniz_oxide, and miniz.

Deflate encoding with and without zlib and gzip metadata (zlib dictionaries are not supported) is supported. No unsafe code is used.

This library is now mostly in maintainance mode, focus being on the rust-backend of [flate2](https://crates.io/crates/flate2) instead.
This library is now mostly in maintenance mode, focus being on the Rust backend of [flate2](https://crates.io/crates/flate2) instead.

# Usage:
## Simple compression function:
Expand All @@ -32,11 +32,11 @@ encoder.write_all(data).unwrap();
let compressed_data = encoder.finish().unwrap();
```

# Other deflate/zlib rust projects from various people
* [flate2](http://alexcrichton.com/flate2-rs/flate2/index.html) FLATE, Gzip, and Zlib bindings for Rust - can use miniz_oxide for a full rust-implemented library.
# Other deflate/zlib Rust projects from various people
* [flate2](http://alexcrichton.com/flate2-rs/flate2/index.html) FLATE, Gzip, and Zlib bindings for Rust - can use miniz_oxide for a pure Rust implementation.
* [Zopfli in Rust](https://github.com/carols10cents/zopfli) Rust port of zopfli
* [inflate](https://github.com/PistonDevelopers/inflate) DEFLATE decoder implemented in rust
* [miniz-oxide](https://github.com/Frommi/miniz_oxide) Port of miniz to rust.
* [inflate](https://github.com/PistonDevelopers/inflate) DEFLATE decoder implemented in Rust
* [miniz-oxide](https://github.com/Frommi/miniz_oxide) Port of miniz to Rust.
* [libflate](https://github.com/sile/libflate) Another DEFLATE/Zlib/Gzip encoder and decoder written in Rust. (Only does some very light compression).

# License
Expand Down
12 changes: 6 additions & 6 deletions src/compression_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Default for Compression {
pub enum SpecialOptions {
/// Compress normally.
Normal,
/// Force fixed huffman tables. (Unimplemented!).
/// Force fixed Huffman tables. (Unimplemented!).
_ForceFixed,
/// Force stored (uncompressed) blocks only. (Unimplemented!).
_ForceStored,
Expand Down Expand Up @@ -90,7 +90,7 @@ pub struct CompressionOptions {
///
/// Higher values degrade compression slightly, but improve compression speed.
///
/// * `0`: Never lazy match. (Same effect as setting MatchingType to greedy, but may be slower).
/// * `0`: Never lazy match. (Same effect as setting `MatchingType` to greedy, but may be slower).
/// * `1...257`: Only check for a better match if the first match was shorter than this value.
/// * `258`: Always lazy match.
///
Expand Down Expand Up @@ -122,7 +122,7 @@ pub struct CompressionOptions {
// Some standard profiles for the compression options.
// Ord should be implemented at some point, but won't yet until the struct is stabilised.
impl CompressionOptions {
/// Returns compression settings rouhgly corresponding to the `HIGH(9)` setting in miniz.
/// Returns compression settings roughly corresponding to the `HIGH(9)` setting in miniz.
pub fn high() -> CompressionOptions {
CompressionOptions {
max_hash_checks: HIGH_MAX_HASH_CHECKS,
Expand All @@ -135,7 +135,7 @@ impl CompressionOptions {
/// Returns a fast set of compression settings
///
/// Ideally this should roughly correspond to the `FAST(1)` setting in miniz.
/// However, that setting makes miniz use a somewhat different algorhithm,
/// However, that setting makes miniz use a somewhat different algorithm,
/// so currently hte fast level in this library is slower and better compressing
/// than the corresponding level in miniz.
pub fn fast() -> CompressionOptions {
Expand All @@ -148,7 +148,7 @@ impl CompressionOptions {
}

/// Returns a set of compression settings that makes the compressor only compress using
/// huffman coding. (Ignoring any length/distance matching)
/// Huffman coding. (Ignoring any length/distance matching)
///
/// This will normally have the worst compression ratio (besides only using uncompressed data),
/// but may be the fastest method in some cases.
Expand All @@ -166,7 +166,7 @@ impl CompressionOptions {
///
/// This is very fast, but tends to compress worse than looking for more matches using hash
/// chains that the slower settings do.
/// Works best on data that has runs of equivialent bytes, like binary or simple images,
/// Works best on data that has runs of equivalent bytes, like binary or simple images,
/// less good for text.
pub fn rle() -> CompressionOptions {
CompressionOptions {
Expand Down
4 changes: 2 additions & 2 deletions src/deflate_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ pub struct DeflateState<W: Write> {
pub lz77_state: LZ77State,
pub input_buffer: InputBuffer,
pub compression_options: CompressionOptions,
/// State the huffman part of the compression and the output buffer.
/// State the Huffman part of the compression and the output buffer.
pub encoder_state: EncoderState,
/// The buffer containing the raw output of the lz77-encoding.
pub lz77_writer: DynamicWriter,
/// Buffers used when generating huffman code lengths.
/// Buffers used when generating Huffman code lengths.
pub length_buffers: LengthBuffers,
/// Total number of bytes consumed/written to the input buffer.
pub bytes_written: u64,
Expand Down
6 changes: 3 additions & 3 deletions src/encoder_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ pub enum BType {
DynamicHuffman = 0b10, // Reserved = 0b11, //Error
}

/// A struct wrapping a writer that writes data compressed using the provided huffman table
/// A struct wrapping a writer that writes data compressed using the provided Huffman table
pub struct EncoderState {
pub huffman_table: HuffmanTable,
pub writer: LsbWriter,
}

impl EncoderState {
/// Creates a new encoder state using the provided huffman table and writer
/// Creates a new encoder state using the provided Huffman table and writer
pub fn new(writer: Vec<u8>) -> EncoderState {
EncoderState {
huffman_table: HuffmanTable::empty(),
Expand All @@ -35,7 +35,7 @@ impl EncoderState {
}

#[cfg(test)]
/// Creates a new encoder state using the fixed huffman table
/// Creates a new encoder state using the fixed Huffman table
pub fn fixed(writer: Vec<u8>) -> EncoderState {
EncoderState {
huffman_table: HuffmanTable::fixed_table(),
Expand Down
26 changes: 13 additions & 13 deletions src/huffman_lengths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ use crate::stored_block::MAX_STORED_BLOCK_LENGTH;

use std::cmp;

// The minimum number of literal/length values
/// The minimum number of literal/length values
pub const MIN_NUM_LITERALS_AND_LENGTHS: usize = 257;
// The minimum number of distances
/// The minimum number of distances
pub const MIN_NUM_DISTANCES: usize = 1;

const NUM_HUFFMAN_LENGTHS: usize = 19;

// The output ordering of the lengths for the huffman codes used to encode the lengths
// used to build the full huffman tree for length/literal codes.
// http://www.gzip.org/zlib/rfc-deflate.html#dyn
/// The output ordering of the lengths for the Huffman codes used to encode the lengths
/// used to build the full Huffman tree for length/literal codes.
/// http://www.gzip.org/zlib/rfc-deflate.html#dyn
const HUFFMAN_LENGTH_ORDER: [u8; NUM_HUFFMAN_LENGTHS] = [
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15,
];
Expand All @@ -33,7 +33,7 @@ const HLIT_BITS: u8 = 5;
const HDIST_BITS: u8 = 5;
const HCLEN_BITS: u8 = 4;

// The longest a huffman code describing another huffman length can be
/// The longest a Huffman code describing another Huffman length can be
const MAX_HUFFMAN_CODE_LENGTH: usize = 7;

// How many bytes (not including padding and the 3-bit block type) the stored block header takes up.
Expand All @@ -46,7 +46,7 @@ pub fn remove_trailing_zeroes<T: From<u8> + PartialEq>(input: &[T], min_length:
&input[0..cmp::max(input.len() - num_zeroes, min_length)]
}

/// How many extra bits the huffman length code uses to represent a value.
/// How many extra bits the Huffman length code uses to represent a value.
fn extra_bits_for_huffman_length_code(code: u8) -> u8 {
match code {
16..=17 => 3,
Expand All @@ -55,7 +55,7 @@ fn extra_bits_for_huffman_length_code(code: u8) -> u8 {
}
}

/// Calculate how many bits the huffman-encoded huffman lengths will use.
/// Calculate how many bits the Huffman-encoded Huffman lengths will use.
fn calculate_huffman_length(frequencies: &[FrequencyType], code_lengths: &[u8]) -> u64 {
frequencies
.iter()
Expand All @@ -72,7 +72,7 @@ fn calculate_huffman_length(frequencies: &[FrequencyType], code_lengths: &[u8])
///
/// Parameters:
/// Frequencies, length of dynamic codes, and a function to get how many extra bits in addition
/// to the length of the huffman code the symbol will use.
/// to the length of the Huffman code the symbol will use.
fn calculate_block_length<F>(
frequencies: &[FrequencyType],
dyn_code_lengths: &[u8],
Expand Down Expand Up @@ -155,12 +155,12 @@ pub enum BlockType {
pub struct DynamicBlockHeader {
/// Length of the run-length encoding symbols.
pub huffman_table_lengths: Vec<u8>,
/// Number of lengths for values describing the huffman table that encodes the length values
/// of the main huffman tables.
/// Number of lengths for values describing the Huffman table that encodes the length values
/// of the main Huffman tables.
pub used_hclens: usize,
}

/// Generate the lengths of the huffman codes we will be using, using the
/// Generate the lengths of the Huffman codes we will be using, using the
/// frequency of the different symbols/lengths/distances, and determine what block type will give
/// the shortest representation.
/// TODO: This needs a test
Expand Down Expand Up @@ -286,7 +286,7 @@ pub fn gen_huffman_lengths(
}
}

/// Write the specified huffman lengths to the bit writer
/// Write the specified Huffman lengths to the bit writer
pub fn write_huffman_lengths(
header: &DynamicBlockHeader,
huffman_table: &HuffmanTable,
Expand Down
Loading

0 comments on commit 2385f2a

Please sign in to comment.