Write match (back-reference to the same data slice) starting at distance
back from current write position, and length of bytes.
fn writeMatch(w: *Writer, length: u16, distance: u16) !void
fn writeMatch(w: *Writer, length: u16, distance: u16) !void {
if (w.end < distance) return error.InvalidMatch;
assert(length >= token.min_length);
assert(length <= token.max_length);
assert(distance >= token.min_distance);
assert(distance <= token.max_distance);
// This is not a @memmove; it intentionally repeats patterns caused by
// iterating one byte at a time.
const dest = try w.writableSlicePreserve(flate.history_len, length);
const end = dest.ptr - w.buffer.ptr;
const src = w.buffer[end - distance ..][0..length];
if (distance >= length) {
@memcpy(dest, src);
} else if (distance == 1) {
// Repeating copy of single byte
@memset(dest, src[0]);
} else {
// Repeating copy of multiple bytes
for (dest, src) |*d, s| d.* = s;
}
}