zig/lib/std/compress/deflate/mem_utils.zig
Hadrien Dorio 490f067de8
compress: add a deflate compressor
Replaces the inflate API from `inflateStream(reader: anytype, window_slice: []u8)` to
`decompressor(allocator: mem.Allocator, reader: anytype, dictionary: ?[]const u8)` and
`compressor(allocator: mem.Allocator, writer: anytype, options: CompressorOptions)`
2022-01-23 19:30:06 +01:00

16 lines
576 B
Zig

const std = @import("std");
const math = std.math;
const mem = std.mem;
// Copies elements from a source `src` slice into a destination `dst` slice.
// The copy never returns an error but might not be complete if the destination is too small.
// Returns the number of elements copied, which will be the minimum of `src.len` and `dst.len`.
pub fn copy(dst: []u8, src: []const u8) usize {
if (dst.len <= src.len) {
mem.copy(u8, dst[0..], src[0..dst.len]);
} else {
mem.copy(u8, dst[0..src.len], src[0..]);
}
return math.min(dst.len, src.len);
}