diff --git a/src/deflate.zig b/src/deflate.zig index 49bbfc2..cd0219a 100644 --- a/src/deflate.zig +++ b/src/deflate.zig @@ -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. @@ -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 { @@ -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" { diff --git a/src/root.zig b/src/root.zig index 4280fd4..5058e2a 100644 --- a/src/root.zig +++ b/src/root.zig @@ -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); } @@ -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); } @@ -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); } @@ -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;