Skip to content

Commit

Permalink
document root
Browse files Browse the repository at this point in the history
  • Loading branch information
ianic committed Feb 6, 2024
1 parent a74c642 commit 353c06e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
11 changes: 8 additions & 3 deletions src/deflate.zig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Container = @import("container.zig").Container;
const SlidingWindow = @import("SlidingWindow.zig");
const Lookup = @import("Lookup.zig");

/// Trades between speed and compression.
/// Trades between speed and compression size.
/// Starts with level 4: in [zlib](https://github.com/madler/zlib/blob/abd3d1a28930f89375d4b41408b39f6c1be157b2/deflate.c#L115C1-L117C43)
/// levels 1-3 are using different algorithm to perform faster but with less
/// compression. That is not implemented here.
Expand Down Expand Up @@ -357,8 +357,9 @@ pub fn huffmanOnlyCompressor(comptime container: Container, writer: anytype) !Hu
return try HuffmanOnlyCompressor(container, @TypeOf(writer)).init(writer);
}

// Creates huffman only deflate blocks. Disables Lempel-Ziv match searching and
// only performs Huffman entropy encoding.
/// Creates huffman only deflate blocks. Disables Lempel-Ziv match searching and
/// only performs Huffman entropy encoding. Results in faster compression, much
/// less memory requirements during compression but bigger compressed sizes.
pub fn HuffmanOnlyCompressor(comptime container: Container, comptime WriterType: type) type {
const BlockWriterType = BlockWriter(WriterType);
return struct {
Expand Down Expand Up @@ -495,6 +496,10 @@ test "check struct sizes" {
// const allocator = la.allocator();
// var cmp = try std.compress.deflate.compressor(allocator, io.null_writer, .{});
// defer cmp.deinit();

const HOC = HuffmanOnlyCompressor(.raw, @TypeOf(io.null_writer));
try expect(@sizeOf(HOC) == 11480);
//print("size of HOC {d}\n", .{@sizeOf(HOC)});
}

test "deflate file tokenization" {
Expand Down
27 changes: 17 additions & 10 deletions src/root.zig
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
/// In computing, Deflate (stylized as DEFLATE, and also called Flate[1][2]) is
/// a lossless data compression file format that uses a combination of LZ77 and
/// Huffman coding. It was designed by Phil Katz, for version 2 of his PKZIP
/// archiving tool. Deflate was later specified in RFC 1951 (1996).[3]
/// Encoder/compressor
///
/// Deflate is a lossless data compression file format that uses a combination
/// of LZ77 and Huffman coding.
pub const deflate = @import("deflate.zig");

/// Inflate is the decoding process that takes a Deflate bitstream for
/// decompression and correctly produces the original full-size data or file.
/// decoder/decompressor
///
pub const deflate = @import("deflate.zig");
pub const inflate = @import("inflate.zig");

pub const Level = @import("deflate.zig").Level;
/// Level trades between speed and compression size.
pub const Level = deflate.Level;

/// Container defines header/footer arround deflate bit stream. Gzip and zlib
/// compression algorithms are container arround deflate bit stream body.
const Container = @import("container.zig").Container;

fn byContainer(comptime container: Container) type {
return struct {
/// Decompress compressed data from reader and write them to the writer.
pub fn decompress(reader: anytype, writer: anytype) !void {
try inflate.decompress(container, reader, writer);
}
Expand All @@ -25,10 +24,12 @@ fn byContainer(comptime container: Container) type {
return inflate.Inflate(container, ReaderType);
}

/// Create Decompressor which read compressed data from reader.
pub fn decompressor(reader: anytype) Decompressor(@TypeOf(reader)) {
return inflate.decompressor(container, reader);
}

/// Compress plain data from reader and write them to the writer.
pub fn compress(reader: anytype, writer: anytype, level: Level) !void {
try deflate.compress(container, reader, writer, level);
}
Expand All @@ -37,6 +38,7 @@ fn byContainer(comptime container: Container) type {
return deflate.Compressor(container, WriterType);
}

/// Create Compressor which outputs compressed data to the writer.
pub fn compressor(writer: anytype, level: Level) !Compressor(@TypeOf(writer)) {
return try deflate.compressor(container, writer, level);
}
Expand All @@ -45,10 +47,15 @@ fn byContainer(comptime container: Container) type {
return deflate.HuffmanOnlyCompressor(container, WriterType);
}

/// Disables Lempel-Ziv match searching and only performs Huffman
/// entropy encoding. Results in faster compression, much less memory
/// requirements during compression but bigger compressed sizes.
pub fn huffmanOnlyCompressor(writer: anytype) !HuffmanOnlyCompressor(@TypeOf(writer)) {
return deflate.huffmanOnlyCompressor(container, writer);
}

/// Compress plain data from reader and write them to the writer using
/// huffman only compression algorithm.
pub fn compressHuffmanOnly(reader: anytype, writer: anytype) !void {
var cmp = try huffmanOnlyCompressor(writer);
var buf: [1024 * 64]u8 = undefined;
Expand Down

0 comments on commit 353c06e

Please sign in to comment.