structstd.compress[src]

Compression algorithms.

Types

Type FunctionHashedReader[src]

Parameters

ReaderType: type
HasherType: type

Types

TypeReader[src]

Source Code

Source code
pub const Reader = std.io.Reader(*@This(), Error, read)

Fields

child_reader: ReaderType
hasher: HasherType

Values

ConstantError[src]

Source Code

Source code
pub const Error = ReaderType.Error

Functions

Functionread[src]

pub fn read(self: *@This(), buf: []u8) Error!usize

Parameters

self: *@This()
buf: []u8

Source Code

Source code
pub fn read(self: *@This(), buf: []u8) Error!usize {
    const amt = try self.child_reader.read(buf);
    self.hasher.update(buf[0..amt]);
    return amt;
}

Functionreader[src]

pub fn reader(self: *@This()) Reader

Parameters

self: *@This()

Source Code

Source code
pub fn reader(self: *@This()) Reader {
    return .{ .context = self };
}

Source Code

Source code
pub fn HashedReader(ReaderType: type, HasherType: type) type {
    return struct {
        child_reader: ReaderType,
        hasher: HasherType,

        pub const Error = ReaderType.Error;
        pub const Reader = std.io.Reader(*@This(), Error, read);

        pub fn read(self: *@This(), buf: []u8) Error!usize {
            const amt = try self.child_reader.read(buf);
            self.hasher.update(buf[0..amt]);
            return amt;
        }

        pub fn reader(self: *@This()) Reader {
            return .{ .context = self };
        }
    };
}

Type FunctionHashedWriter[src]

Parameters

WriterType: type
HasherType: type

Types

TypeWriter[src]

Source Code

Source code
pub const Writer = std.io.Writer(*@This(), Error, write)

Fields

child_writer: WriterType
hasher: HasherType

Values

ConstantError[src]

Source Code

Source code
pub const Error = WriterType.Error

Functions

Functionwrite[src]

pub fn write(self: *@This(), buf: []const u8) Error!usize

Parameters

self: *@This()
buf: []const u8

Source Code

Source code
pub fn write(self: *@This(), buf: []const u8) Error!usize {
    const amt = try self.child_writer.write(buf);
    self.hasher.update(buf[0..amt]);
    return amt;
}

Functionwriter[src]

pub fn writer(self: *@This()) Writer

Parameters

self: *@This()

Source Code

Source code
pub fn writer(self: *@This()) Writer {
    return .{ .context = self };
}

Source Code

Source code
pub fn HashedWriter(WriterType: type, HasherType: type) type {
    return struct {
        child_writer: WriterType,
        hasher: HasherType,

        pub const Error = WriterType.Error;
        pub const Writer = std.io.Writer(*@This(), Error, write);

        pub fn write(self: *@This(), buf: []const u8) Error!usize {
            const amt = try self.child_writer.write(buf);
            self.hasher.update(buf[0..amt]);
            return amt;
        }

        pub fn writer(self: *@This()) Writer {
            return .{ .context = self };
        }
    };
}

Functions

FunctionhashedReader[src]

pub fn hashedReader( reader: anytype, hasher: anytype, ) HashedReader(@TypeOf(reader), @TypeOf(hasher))

Source Code

Source code
pub fn hashedReader(
    reader: anytype,
    hasher: anytype,
) HashedReader(@TypeOf(reader), @TypeOf(hasher)) {
    return .{ .child_reader = reader, .hasher = hasher };
}

FunctionhashedWriter[src]

pub fn hashedWriter( writer: anytype, hasher: anytype, ) HashedWriter(@TypeOf(writer), @TypeOf(hasher))

Source Code

Source code
pub fn hashedWriter(
    writer: anytype,
    hasher: anytype,
) HashedWriter(@TypeOf(writer), @TypeOf(hasher)) {
    return .{ .child_writer = writer, .hasher = hasher };
}

Source Code

Source code
//! Compression algorithms.

const std = @import("std.zig");

pub const flate = @import("compress/flate.zig");
pub const gzip = @import("compress/gzip.zig");
pub const zlib = @import("compress/zlib.zig");
pub const lzma = @import("compress/lzma.zig");
pub const lzma2 = @import("compress/lzma2.zig");
pub const xz = @import("compress/xz.zig");
pub const zstd = @import("compress/zstandard.zig");

pub fn HashedReader(ReaderType: type, HasherType: type) type {
    return struct {
        child_reader: ReaderType,
        hasher: HasherType,

        pub const Error = ReaderType.Error;
        pub const Reader = std.io.Reader(*@This(), Error, read);

        pub fn read(self: *@This(), buf: []u8) Error!usize {
            const amt = try self.child_reader.read(buf);
            self.hasher.update(buf[0..amt]);
            return amt;
        }

        pub fn reader(self: *@This()) Reader {
            return .{ .context = self };
        }
    };
}

pub fn hashedReader(
    reader: anytype,
    hasher: anytype,
) HashedReader(@TypeOf(reader), @TypeOf(hasher)) {
    return .{ .child_reader = reader, .hasher = hasher };
}

pub fn HashedWriter(WriterType: type, HasherType: type) type {
    return struct {
        child_writer: WriterType,
        hasher: HasherType,

        pub const Error = WriterType.Error;
        pub const Writer = std.io.Writer(*@This(), Error, write);

        pub fn write(self: *@This(), buf: []const u8) Error!usize {
            const amt = try self.child_writer.write(buf);
            self.hasher.update(buf[0..amt]);
            return amt;
        }

        pub fn writer(self: *@This()) Writer {
            return .{ .context = self };
        }
    };
}

pub fn hashedWriter(
    writer: anytype,
    hasher: anytype,
) HashedWriter(@TypeOf(writer), @TypeOf(hasher)) {
    return .{ .child_writer = writer, .hasher = hasher };
}

test {
    _ = lzma;
    _ = lzma2;
    _ = xz;
    _ = zstd;
    _ = flate;
    _ = gzip;
    _ = zlib;
}