Skip to content

Commit fb83d07

Browse files
committed
[Library] Reorganize
1 parent 8e5d3f7 commit fb83d07

13 files changed

+46
-48
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
1-
public class BufferedStream<T: Stream>: Stream {
2-
public let inputStream: BufferedInputStream<T>
3-
public let outputStream: BufferedOutputStream<T>
4-
5-
@inline(__always)
6-
public init(baseStream: T, capacity: Int = 4096) {
7-
inputStream = BufferedInputStream(
8-
baseStream: baseStream, capacity: capacity)
9-
outputStream = BufferedOutputStream(
10-
baseStream: baseStream, capacity: capacity)
11-
}
12-
13-
@inline(__always)
14-
public func read(
15-
to buffer: UnsafeMutableRawPointer,
16-
byteCount: Int
17-
) async throws -> Int {
18-
return try await inputStream.read(to: buffer, byteCount: byteCount)
19-
}
20-
21-
@inline(__always)
22-
public func write(
23-
from buffer: UnsafeRawPointer,
24-
byteCount: Int
25-
) async throws -> Int {
26-
return try await outputStream.write(from: buffer, byteCount: byteCount)
27-
}
28-
29-
@inline(__always)
30-
public func flush() async throws {
31-
try await outputStream.flush()
32-
}
33-
}
34-
351
extension BufferedStream: StreamReader {
362
public func cache(count: Int) async throws -> Bool {
373
return try await inputStream.cache(count: count)
@@ -83,17 +49,3 @@ extension BufferedStream: StreamReader {
8349
try await inputStream.consume(mode: mode, while: predicate)
8450
}
8551
}
86-
87-
extension BufferedStream: StreamWriter {
88-
public func write(_ byte: UInt8) async throws {
89-
try await outputStream.write(byte)
90-
}
91-
92-
public func write<T: FixedWidthInteger>(_ value: T) async throws {
93-
try await outputStream.write(value)
94-
}
95-
96-
public func write(_ bytes: UnsafeRawPointer, byteCount: Int) async throws {
97-
try await outputStream.write(bytes, byteCount: byteCount)
98-
}
99-
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extension BufferedStream: StreamWriter {
2+
public func write(_ byte: UInt8) async throws {
3+
try await outputStream.write(byte)
4+
}
5+
6+
public func write<T: FixedWidthInteger>(_ value: T) async throws {
7+
try await outputStream.write(value)
8+
}
9+
10+
public func write(_ bytes: UnsafeRawPointer, byteCount: Int) async throws {
11+
try await outputStream.write(bytes, byteCount: byteCount)
12+
}
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
public class BufferedStream<T: Stream>: Stream {
2+
public let inputStream: BufferedInputStream<T>
3+
public let outputStream: BufferedOutputStream<T>
4+
5+
@inline(__always)
6+
public init(baseStream: T, capacity: Int = 4096) {
7+
inputStream = BufferedInputStream(
8+
baseStream: baseStream, capacity: capacity)
9+
outputStream = BufferedOutputStream(
10+
baseStream: baseStream, capacity: capacity)
11+
}
12+
13+
@inline(__always)
14+
public func read(
15+
to buffer: UnsafeMutableRawPointer,
16+
byteCount: Int
17+
) async throws -> Int {
18+
return try await inputStream.read(to: buffer, byteCount: byteCount)
19+
}
20+
21+
@inline(__always)
22+
public func write(
23+
from buffer: UnsafeRawPointer,
24+
byteCount: Int
25+
) async throws -> Int {
26+
return try await outputStream.write(from: buffer, byteCount: byteCount)
27+
}
28+
29+
@inline(__always)
30+
public func flush() async throws {
31+
try await outputStream.flush()
32+
}
33+
}

0 commit comments

Comments
 (0)