zlib-based homecooked gzip reader for significantly faster decompression times

This commit is contained in:
2024-11-12 09:37:46 +11:00
parent cf5e1a3f35
commit 089a7dcfe1
7 changed files with 256 additions and 14 deletions

View File

@ -52,6 +52,15 @@ public struct MemoryInputStream: InputStream {
return bytes
}
public mutating func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength count: Int) throws(StreamError) -> Int {
let beg = min(self._idx, self._len)
let end = min(self._idx + count, self._len)
let len = beg.distance(to: end)
let buf = UnsafeMutableRawBufferPointer(start: buffer, count: len)
self._idx += len
return self._sli.copyBytes(to: buf, from: beg..<end)
}
public mutating func next() -> UInt8? {
if self._idx < self._len {
let byte = self._sli[self._idx]