Skip to content

Commit 4ee9246

Browse files
committed
Rename Input(Output)ByteStream to ByteArrayIntput(Output)Stream
1 parent 4400d23 commit 4ee9246

File tree

18 files changed

+53
-47
lines changed

18 files changed

+53
-47
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ addTestSuite(name: "Stream/BufferedOutputStream")
2525
addTestSuite(name: "Stream/BufferedStream")
2626
addTestSuite(name: "Stream/BufferedStreamReader")
2727
addTestSuite(name: "Stream/BufferedStreamWriter")
28-
addTestSuite(name: "Stream/InputByteStream")
28+
addTestSuite(name: "Stream/ByteArrayInputStream")
29+
addTestSuite(name: "Stream/ByteArrayOutputStream")
2930
addTestSuite(name: "Stream/MemoryStream")
3031
addTestSuite(name: "Stream/Numeric")
31-
addTestSuite(name: "Stream/OutputByteStream")
3232
addTestSuite(name: "Stream/Stream")
3333
addTestSuite(name: "Stream/StreamReader")
3434
addTestSuite(name: "Stream/SubStreamReader")

Sources/Stream/Library/ByteStream/InputByteStream+StreamReader.swift renamed to Sources/Stream/Library/ByteArrayStream/ByteArrayInputStream+StreamReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension InputByteStream: StreamReader {
1+
extension ByteArrayInputStream: StreamReader {
22
public var buffered: Int {
33
return bytes.count - position
44
}

Sources/Stream/Library/ByteStream/InputByteStream.swift renamed to Sources/Stream/Library/ByteArrayStream/ByteArrayInputStream.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public class InputByteStream: InputStream {
1+
public class ByteArrayInputStream: InputStream {
22
public let bytes: [UInt8]
33
public internal(set) var position = 0
44
public var isEmpty: Bool { position == bytes.count }
@@ -23,3 +23,6 @@ public class InputByteStream: InputStream {
2323
return count
2424
}
2525
}
26+
27+
@available(*, renamed: "ByteArrayInputStream")
28+
public typealias InputByteStream = ByteArrayInputStream

Sources/Stream/Library/ByteStream/OutputByteStream+StreamWriter.swift renamed to Sources/Stream/Library/ByteArrayStream/ByteArrayOutputStream+StreamWriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension OutputByteStream: StreamWriter {
1+
extension ByteArrayOutputStream: StreamWriter {
22
public var buffered: Int {
33
return bytes.count - position
44
}

Sources/Stream/Library/ByteStream/OutputByteStream.swift renamed to Sources/Stream/Library/ByteArrayStream/ByteArrayOutputStream.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public class OutputByteStream: OutputStream {
1+
public class ByteArrayOutputStream: OutputStream {
22
public var bytes: [UInt8]
33
public var position: Int { bytes.count }
44
public var stringValue: String { .init(decoding: bytes, as: UTF8.self) }
@@ -19,3 +19,6 @@ public class OutputByteStream: OutputStream {
1919
return byteCount
2020
}
2121
}
22+
23+
@available(*, renamed: "ByteArrayOutputStream")
24+
public typealias OutputByteStream = ByteArrayOutputStream

Sources/Stream/SubStreamReader.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ public protocol SubStreamReader: StreamReader {
33
var isEmpty: Bool { get }
44
}
55

6-
extension InputByteStream: SubStreamReader {
6+
extension ByteArrayInputStream: SubStreamReader {
77
public var limit: Int {
88
return bytes.count
99
}
@@ -27,7 +27,7 @@ extension StreamReader {
2727
{
2828
// FIXME: [Concurrency] optimize
2929
let bytes = try await read(count: limit)
30-
let stream = InputByteStream(bytes)
30+
let stream = ByteArrayInputStream(bytes)
3131
return try await body(stream)
3232
}
3333
}

Sources/Stream/SubStreamWriter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ public protocol SubStreamWriter: StreamWriter {
22
var count: Int { get }
33
}
44

5-
extension OutputByteStream: SubStreamWriter {
5+
extension ByteArrayOutputStream: SubStreamWriter {
66
public var count: Int {
77
return bytes.count
88
}
@@ -14,7 +14,7 @@ extension StreamWriter {
1414
includingHeader: Bool = false,
1515
task: (SubStreamWriter) async throws -> Void) async throws
1616
{
17-
let output = OutputByteStream()
17+
let output = ByteArrayOutputStream()
1818
try await task(output)
1919
let sizeHeader = includingHeader
2020
? Size(output.bytes.count + MemoryLayout<Size>.size)

Tests/Stream/BufferedInputStream/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test.case("BufferedInputStream") {
5757
}
5858

5959
test.case("BufferedInputStreamDefaultCapacity") {
60-
let stream = BufferedInputStream(baseStream: InputByteStream([]))
60+
let stream = BufferedInputStream(baseStream: ByteArrayInputStream([]))
6161
expect(stream.allocated == 256)
6262
expect(stream.buffered == 0)
6363
}

Tests/Stream/BufferedOutputStream/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Test
22
@testable import Stream
33

44
test.case("BufferedOutputStream") {
5-
let byteStream = OutputByteStream()
5+
let byteStream = ByteArrayOutputStream()
66
let stream = BufferedOutputStream(baseStream: byteStream, capacity: 10)
77
expect(stream.allocated == 10)
88
expect(stream.buffered == 0)
@@ -43,7 +43,7 @@ test.case("BufferedOutputStream") {
4343
}
4444

4545
test.case("BufferedOutputStreamDefaultCapacity") {
46-
let stream = BufferedOutputStream(baseStream: OutputByteStream())
46+
let stream = BufferedOutputStream(baseStream: ByteArrayOutputStream())
4747
expect(stream.allocated == 256)
4848
expect(stream.buffered == 0)
4949
}

Tests/Stream/BufferedStreamReader/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ test.case("ConsumeUntil") {
349349
}
350350

351351
test.case("ConsumeEmpty") {
352-
let stream = BufferedInputStream(baseStream: InputByteStream([]))
352+
let stream = BufferedInputStream(baseStream: ByteArrayInputStream([]))
353353
expect(throws: StreamError.insufficientData) {
354354
try await stream.consume(count: 1)
355355
}
@@ -368,15 +368,15 @@ test.case("FeedLessThanReadCount") {
368368

369369
test.case("AdvancePositionBeforeCallback") {
370370
let stream = BufferedInputStream(
371-
baseStream: InputByteStream([0,1,2,3,4,5,6,7,8,9]))
371+
baseStream: ByteArrayInputStream([0,1,2,3,4,5,6,7,8,9]))
372372
try await stream.readUntilEnd { bytes in
373373
expect(stream.readPosition == stream.writePosition)
374374
}
375375
}
376376

377377
test.case("ReadLine") {
378378
let stream = BufferedInputStream(
379-
baseStream: InputByteStream([UInt8]("line1\r\nline2\n".utf8)))
379+
baseStream: ByteArrayInputStream([UInt8]("line1\r\nline2\n".utf8)))
380380
expect(try await stream.readLine() == "line1")
381381
expect(try await stream.readLine() == "line2")
382382
}

Tests/Stream/BufferedStreamWriter/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Test
22
@testable import Stream
33

44
test.case("WriteByte") {
5-
let stream = OutputByteStream()
5+
let stream = ByteArrayOutputStream()
66
let output = BufferedOutputStream(baseStream: stream, capacity: 5)
77

88
try await output.write(UInt8(42))

Tests/Stream/InputByteStream/main.swift renamed to Tests/Stream/ByteArrayInputStream/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Test
22
@testable import Stream
33

4-
test.case("InputByteStream") {
5-
let inputStream = InputByteStream([])
4+
test.case("ByteArrayInputStream") {
5+
let inputStream = ByteArrayInputStream([])
66
var buffer = [UInt8]()
77
expect(try inputStream.read(to: &buffer, byteCount: 0) == 0)
88
}
99

10-
test.case("InputByteStream advance position before callback") {
11-
let input = InputByteStream([0,1,2,3,4,5,6,7,8,9])
10+
test.case("ByteArrayInputStream advance position before callback") {
11+
let input = ByteArrayInputStream([0,1,2,3,4,5,6,7,8,9])
1212
try await input.readUntilEnd { bytes in
1313
expect(input.position == input.bytes.count)
1414
}

Tests/Stream/OutputByteStream/main.swift renamed to Tests/Stream/ByteArrayOutputStream/main.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Test
22
@testable import Stream
33

4-
test.case("OutputByteStream") {
5-
let outputStream = OutputByteStream()
4+
test.case("ByteArrayOutputStream") {
5+
let outputStream = ByteArrayOutputStream()
66
let bytes = [UInt8]()
77
expect(try outputStream.write(from: bytes, byteCount: 0) == 0)
88
}
99

10-
test.case("OutputByteStream Numeric") {
11-
let outputStream = OutputByteStream()
10+
test.case("ByteArrayOutputStream Numeric") {
11+
let outputStream = ByteArrayOutputStream()
1212

1313
try outputStream.write(Int(-1))
1414
try outputStream.write(Int8(-2))
@@ -21,7 +21,7 @@ test.case("OutputByteStream Numeric") {
2121
try outputStream.write(UInt32(4))
2222
try outputStream.write(UInt64(5))
2323

24-
let inputStream = InputByteStream(outputStream.bytes)
24+
let inputStream = ByteArrayInputStream(outputStream.bytes)
2525

2626
expect(try inputStream.read(Int.self) == -1)
2727
expect(try inputStream.read(Int8.self) == -2)

Tests/Stream/Numeric/main.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import Test
22
import Stream
33

44
test.case("Int") {
5-
expect(try await InputByteStream("42").parse(Int.self) == 42)
6-
expect(try await InputByteStream("3.14").parse(Int.self) == 3)
7-
expect(try await InputByteStream("-42").parse(Int.self) == -42)
5+
expect(try await ByteArrayInputStream("42").parse(Int.self) == 42)
6+
expect(try await ByteArrayInputStream("3.14").parse(Int.self) == 3)
7+
expect(try await ByteArrayInputStream("-42").parse(Int.self) == -42)
88
}
99

1010
test.case("Double") {
11-
expect(try await InputByteStream("0.1").parse(Double.self) == 0.1)
12-
expect(try await InputByteStream("1.0").parse(Double.self) == 1.0)
13-
expect(try await InputByteStream("0.7").parse(Double.self) == 0.7)
14-
expect(try await InputByteStream("3.14").parse(Double.self) == 3.14)
15-
expect(try await InputByteStream("42").parse(Double.self) == 42)
16-
expect(try await InputByteStream("42.").parse(Double.self) == 42)
11+
expect(try await ByteArrayInputStream("0.1").parse(Double.self) == 0.1)
12+
expect(try await ByteArrayInputStream("1.0").parse(Double.self) == 1.0)
13+
expect(try await ByteArrayInputStream("0.7").parse(Double.self) == 0.7)
14+
expect(try await ByteArrayInputStream("3.14").parse(Double.self) == 3.14)
15+
expect(try await ByteArrayInputStream("42").parse(Double.self) == 42)
16+
expect(try await ByteArrayInputStream("42.").parse(Double.self) == 42)
1717
}
1818

1919
test.run()

Tests/Stream/StreamReader/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ import Test
33

44
test.case("UntilEnd") {
55
let helloBytes = [UInt8]("Hello, World!".utf8)
6-
let stream = InputByteStream(helloBytes)
6+
let stream = ByteArrayInputStream(helloBytes)
77
let bytes = try await stream.readUntilEnd()
88
expect(bytes == helloBytes)
99
}
1010

1111
test.case("UntilEndAsString") {
1212
let helloString = "Hello, World!"
1313
let helloBytes = [UInt8](helloString.utf8)
14-
let stream = InputByteStream(helloBytes)
14+
let stream = ByteArrayInputStream(helloBytes)
1515
let string = try await stream.readUntilEnd(as: String.self)
1616
expect(string == helloString)
1717
}
1818

1919
test.case("ReadLine") {
2020
let lines = "Hello, World!\r\nHello, World!\r\n"
21-
let stream = InputByteStream([UInt8](lines.utf8))
22-
21+
let stream = ByteArrayInputStream([UInt8](lines.utf8))
22+
2323
expect(try await stream.readLine() == "Hello, World!")
2424
expect(try await stream.readLine() == "Hello, World!")
2525
expect(try await stream.readLine() == nil)

Tests/Stream/SubStreamReader/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import Test
22
@testable import Stream
33

44
test.case("LimitedBy") {
5-
let stream = InputByteStream([UInt8]("Hello, World!".utf8))
6-
let hello = try await stream.withSubStreamReader(limitedBy: 5) { stream in
5+
let stream = ByteArrayInputStream([UInt8]("Hello, World!".utf8))
6+
let hello = try await stream.withSubStreamReader(limitedBy: 5) { stream in
77
return try await stream.readUntilEnd(as: String.self)
88
}
99
try stream.consume(count: 2)
@@ -14,7 +14,7 @@ test.case("LimitedBy") {
1414

1515
test.case("SizedBy") {
1616
let bytes = [0x00, 0x05] + [UInt8]("Hello, World!".utf8)
17-
let stream = InputByteStream(bytes)
17+
let stream = ByteArrayInputStream(bytes)
1818
let hello = try await stream.withSubStreamReader(sizedBy: UInt16.self)
1919
{ stream in
2020
return try await stream.readUntilEnd(as: String.self)
@@ -27,7 +27,7 @@ test.case("SizedBy") {
2727

2828
test.case("SizedByIncludingHeader") {
2929
let bytes = [0x00, 0x07] + [UInt8]("Hello, World!".utf8)
30-
let stream = InputByteStream(bytes)
30+
let stream = ByteArrayInputStream(bytes)
3131
let hello = try await stream.withSubStreamReader(
3232
sizedBy: UInt16.self,
3333
includingHeader: true)

Tests/Stream/SubStreamWriter/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Test
33

44
// FIXME: [Concurrency] crash on m1
55
test.case("SizedBy") {
6-
let stream = OutputByteStream()
6+
let stream = ByteArrayOutputStream()
77
try await stream.withSubStreamWriter(sizedBy: UInt16.self) { stream in
88
return try await stream.write("Hello, World!")
99
}
@@ -12,7 +12,7 @@ test.case("SizedBy") {
1212
}
1313

1414
test.case("SizedByIncludingHeader") {
15-
let stream = OutputByteStream()
15+
let stream = ByteArrayOutputStream()
1616
try await stream.withSubStreamWriter(
1717
sizedBy: UInt16.self,
1818
includingHeader: true)

run_tests

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export DYLD_LIBRARY_PATH=/Library/Developer/Toolchains/swift-latest.xctoolchain/
1111
.build/debug/Tests/Stream/BufferedStream
1212
.build/debug/Tests/Stream/BufferedStreamReader
1313
.build/debug/Tests/Stream/BufferedStreamWriter
14-
.build/debug/Tests/Stream/InputByteStream
14+
.build/debug/Tests/Stream/ByteArrayInputStream
15+
.build/debug/Tests/Stream/ByteArrayOutputStream
1516
.build/debug/Tests/Stream/MemoryStream
1617
.build/debug/Tests/Stream/Numeric
17-
.build/debug/Tests/Stream/OutputByteStream
1818
.build/debug/Tests/Stream/Stream
1919
.build/debug/Tests/Stream/StreamReader
2020
.build/debug/Tests/Stream/SubStreamReader

0 commit comments

Comments
 (0)