yep steam classes are faster...

This commit is contained in:
2024-11-14 00:57:29 +11:00
parent 451deb6aa3
commit da14fa8fd0
7 changed files with 54 additions and 38 deletions

View File

@ -5,19 +5,24 @@
import Foundation
public protocol InputStream: Stream, IteratorProtocol where Element == UInt8 {
mutating func read(_ count: Int) throws(StreamError) -> Data
mutating func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength len: Int) throws(StreamError) -> Int
}
public class InputStream: Stream, IteratorProtocol {
public typealias Element = UInt8
public extension InputStream {
mutating func read(_ size: Int, items: Int) throws(StreamError) -> Data {
try self.read(size * items)
public func read(_ count: Int) throws(StreamError) -> Data {
throw .notImplemented
}
}
public extension InputStream {
mutating func next() -> UInt8? {
public func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength len: Int) throws(StreamError) -> Int {
throw .notImplemented
}
public func next() -> UInt8? {
try? self.read(1).first
}
}
public extension InputStream {
func read(_ size: Int, items: Int) throws(StreamError) -> Data {
try self.read(size * items)
}
}