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

@ -4,6 +4,8 @@
*/
import Foundation
import Darwin
import System
public struct FileInputStream: InputStream {
private var _hnd: FileHandle
@ -72,4 +74,12 @@ public struct FileInputStream: InputStream {
throw .fileHandleError(error)
}
}
public mutating func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength len: Int) throws(StreamError) -> Int {
let res = unistd.read(self._hnd.fileDescriptor, buffer, len)
if res < 0 {
throw .fileHandleError(Errno(rawValue: errno))
}
return res
}
}