~aldats/the

d027301778828aeb1435fd9141638f3a5a29c879 — aldats 1 year, 9 months ago fa33eb6
refactor: `main.zig` require `huffman.zig` only
2 files changed, 5 insertions(+), 3 deletions(-)

M src/huffman.zig
M src/main.zig
M src/huffman.zig => src/huffman.zig +3 -0
@@ 2,6 2,7 @@ const std = @import("std");
const frequencies = @import("frequencies.zig");
const tree = @import("tree.zig");
const canonical = @import("canonical.zig");
const xcoding = @import("xcoding.zig");

const Allocator = std.mem.Allocator;
const File = std.fs.File;


@@ 19,6 20,8 @@ pub const Codebook = canonical.Codebook;

pub const getFrequencies = frequencies.getFrequencies;
pub const getLengthCount = canonical.getLengthCount;
pub const compress = xcoding.compress;
pub const decompress = xcoding.decompress;

/// Struct containing a character and its absolute frequency within a
/// read file.

M src/main.zig => src/main.zig +2 -3
@@ 1,7 1,6 @@
const std = @import("std");
const meno = @import("meno");
const huffman = @import("huffman.zig");
const xcoding = @import("xcoding.zig");

const Allocator = std.mem.Allocator;
const Reader = std.fs.File.Reader;


@@ 95,7 94,7 @@ fn compress(from_path: []const u8, to_path: []const u8, allocator: Allocator) !v
    const writer = result.writer();

    try file.seekTo(0);
    try xcoding.compress(reader, writer, frequencies, allocator);
    try huffman.compress(reader, writer, frequencies, allocator);

    return;
}


@@ 111,7 110,7 @@ fn decompress(from_path: []const u8, to_path: []const u8, allocator: Allocator) 
    var bw = std.io.bufferedWriter(decoded_file.writer());
    const writer = bw.writer();

    try xcoding.decompress(reader, writer, allocator);
    try huffman.decompress(reader, writer, allocator);

    try bw.flush();