@@ -18,7 +18,7 @@ private func hexdigit(_ value: UInt8) -> UInt8 {
18
18
19
19
/// Describes a type which can be written to a byte stream.
20
20
public protocol ByteStreamable {
21
- func write( to stream: OutputByteStream )
21
+ func write( to stream: WritableByteStream )
22
22
}
23
23
24
24
/// An output byte stream.
@@ -43,7 +43,7 @@ public protocol ByteStreamable {
43
43
///
44
44
/// would write each item in the list to the stream, separating them with a
45
45
/// space.
46
- public protocol OutputByteStream : class , TextOutputStream {
46
+ public protocol WritableByteStream : class , TextOutputStream {
47
47
/// The current offset within the output stream.
48
48
var position : Int { get }
49
49
@@ -57,7 +57,10 @@ public protocol OutputByteStream: class, TextOutputStream {
57
57
func flush( )
58
58
}
59
59
60
- extension OutputByteStream {
60
+ // Public alias to the old name to not introduce API compatibility.
61
+ public typealias OutputByteStream = WritableByteStream
62
+
63
+ extension WritableByteStream {
61
64
/// Write a sequence of bytes to the buffer.
62
65
public func write< S: Sequence > ( sequence: S ) where S. Iterator. Element == UInt8 {
63
66
// Iterate the sequence and append byte by byte since sequence's append
@@ -124,12 +127,12 @@ extension OutputByteStream {
124
127
}
125
128
}
126
129
127
- /// The `OutputByteStream ` base class.
130
+ /// The `WritableByteStream ` base class.
128
131
///
129
- /// This class provides a base and efficient implementation of the `OutputByteStream `
132
+ /// This class provides a base and efficient implementation of the `WritableByteStream `
130
133
/// protocol. It can not be used as is-as subclasses as several functions need to be
131
134
/// implemented in subclasses.
132
- public class _OutputByteStreamBase : OutputByteStream {
135
+ public class _WritableByteStreamBase : WritableByteStream {
133
136
/// If buffering is enabled
134
137
@usableFromInline let _buffered : Bool
135
138
@@ -149,7 +152,7 @@ public class _OutputByteStreamBase: OutputByteStream {
149
152
150
153
// When not buffered we still reserve 1 byte, as it is used by the
151
154
// by the single byte write() variant.
152
- self . _buffer. reserveCapacity ( buffered ? _OutputByteStreamBase . bufferSize : 1 )
155
+ self . _buffer. reserveCapacity ( buffered ? _WritableByteStreamBase . bufferSize : 1 )
153
156
}
154
157
155
158
// MARK: Data Access API
@@ -268,13 +271,13 @@ public class _OutputByteStreamBase: OutputByteStream {
268
271
269
272
/// The thread-safe wrapper around output byte streams.
270
273
///
271
- /// This class wraps any `OutputByteStream ` conforming type to provide a type-safe
272
- /// access to its operations. If the provided stream inherits from `_OutputByteStreamBase `,
274
+ /// This class wraps any `WritableByteStream ` conforming type to provide a type-safe
275
+ /// access to its operations. If the provided stream inherits from `_WritableByteStreamBase `,
273
276
/// it will also ensure it is type-safe will all other `ThreadSafeOutputByteStream` instances
274
277
/// around the same stream.
275
- public final class ThreadSafeOutputByteStream : OutputByteStream {
278
+ public final class ThreadSafeOutputByteStream : WritableByteStream {
276
279
private static let defaultQueue = DispatchQueue ( label: " org.swift.swiftpm.basic.thread-safe-output-byte-stream " )
277
- public let stream : OutputByteStream
280
+ public let stream : WritableByteStream
278
281
private let queue : DispatchQueue
279
282
280
283
public var position : Int {
@@ -283,9 +286,9 @@ public final class ThreadSafeOutputByteStream: OutputByteStream {
283
286
}
284
287
}
285
288
286
- public init ( _ stream: OutputByteStream ) {
289
+ public init ( _ stream: WritableByteStream ) {
287
290
self . stream = stream
288
- self . queue = ( stream as? _OutputByteStreamBase ) ? . queue ?? ThreadSafeOutputByteStream . defaultQueue
291
+ self . queue = ( stream as? _WritableByteStreamBase ) ? . queue ?? ThreadSafeOutputByteStream . defaultQueue
289
292
}
290
293
291
294
public func write( _ byte: UInt8 ) {
@@ -331,73 +334,73 @@ precedencegroup StreamingPrecedence {
331
334
// FIXME: This override shouldn't be necesary but removing it causes a 30% performance regression. This problem is
332
335
// tracked by the following bug: https://bugs.swift.org/browse/SR-8535
333
336
@discardableResult
334
- public func <<< ( stream: OutputByteStream , value: ArraySlice < UInt8 > ) -> OutputByteStream {
337
+ public func <<< ( stream: WritableByteStream , value: ArraySlice < UInt8 > ) -> WritableByteStream {
335
338
value. write ( to: stream)
336
339
return stream
337
340
}
338
341
339
342
@discardableResult
340
- public func <<< ( stream: OutputByteStream , value: ByteStreamable ) -> OutputByteStream {
343
+ public func <<< ( stream: WritableByteStream , value: ByteStreamable ) -> WritableByteStream {
341
344
value. write ( to: stream)
342
345
return stream
343
346
}
344
347
345
348
@discardableResult
346
- public func <<< ( stream: OutputByteStream , value: CustomStringConvertible ) -> OutputByteStream {
349
+ public func <<< ( stream: WritableByteStream , value: CustomStringConvertible ) -> WritableByteStream {
347
350
value. description. write ( to: stream)
348
351
return stream
349
352
}
350
353
351
354
@discardableResult
352
- public func <<< ( stream: OutputByteStream , value: ByteStreamable & CustomStringConvertible ) -> OutputByteStream {
355
+ public func <<< ( stream: WritableByteStream , value: ByteStreamable & CustomStringConvertible ) -> WritableByteStream {
353
356
value. write ( to: stream)
354
357
return stream
355
358
}
356
359
357
360
extension UInt8 : ByteStreamable {
358
- public func write( to stream: OutputByteStream ) {
361
+ public func write( to stream: WritableByteStream ) {
359
362
stream. write ( self )
360
363
}
361
364
}
362
365
363
366
extension Character : ByteStreamable {
364
- public func write( to stream: OutputByteStream ) {
367
+ public func write( to stream: WritableByteStream ) {
365
368
stream. write ( String ( self ) )
366
369
}
367
370
}
368
371
369
372
extension String : ByteStreamable {
370
- public func write( to stream: OutputByteStream ) {
373
+ public func write( to stream: WritableByteStream ) {
371
374
stream. write ( self . utf8)
372
375
}
373
376
}
374
377
375
378
extension Substring : ByteStreamable {
376
- public func write( to stream: OutputByteStream ) {
379
+ public func write( to stream: WritableByteStream ) {
377
380
stream. write ( self . utf8)
378
381
}
379
382
}
380
383
381
384
extension StaticString : ByteStreamable {
382
- public func write( to stream: OutputByteStream ) {
385
+ public func write( to stream: WritableByteStream ) {
383
386
withUTF8Buffer { stream. write ( $0) }
384
387
}
385
388
}
386
389
387
390
extension Array : ByteStreamable where Element == UInt8 {
388
- public func write( to stream: OutputByteStream ) {
391
+ public func write( to stream: WritableByteStream ) {
389
392
stream. write ( self )
390
393
}
391
394
}
392
395
393
396
extension ArraySlice : ByteStreamable where Element == UInt8 {
394
- public func write( to stream: OutputByteStream ) {
397
+ public func write( to stream: WritableByteStream ) {
395
398
stream. write ( self )
396
399
}
397
400
}
398
401
399
402
extension ContiguousArray : ByteStreamable where Element == UInt8 {
400
- public func write( to stream: OutputByteStream ) {
403
+ public func write( to stream: WritableByteStream ) {
401
404
stream. write ( self )
402
405
}
403
406
}
@@ -413,7 +416,7 @@ public struct Format {
413
416
private struct JSONEscapedBoolStreamable : ByteStreamable {
414
417
let value : Bool
415
418
416
- func write( to stream: OutputByteStream ) {
419
+ func write( to stream: WritableByteStream ) {
417
420
stream <<< ( value ? " true " : " false " )
418
421
}
419
422
}
@@ -425,7 +428,7 @@ public struct Format {
425
428
private struct JSONEscapedIntStreamable : ByteStreamable {
426
429
let value : Int
427
430
428
- func write( to stream: OutputByteStream ) {
431
+ func write( to stream: WritableByteStream ) {
429
432
// FIXME: Diagnose integers which cannot be represented in JSON.
430
433
stream <<< value. description
431
434
}
@@ -438,7 +441,7 @@ public struct Format {
438
441
private struct JSONEscapedDoubleStreamable : ByteStreamable {
439
442
let value : Double
440
443
441
- func write( to stream: OutputByteStream ) {
444
+ func write( to stream: WritableByteStream ) {
442
445
// FIXME: What should we do about NaN, etc.?
443
446
//
444
447
// FIXME: Is Double.debugDescription the best representation?
@@ -457,7 +460,7 @@ public struct Format {
457
460
private struct JSONEscapedStringStreamable : ByteStreamable {
458
461
let value : String
459
462
460
- func write( to stream: OutputByteStream ) {
463
+ func write( to stream: WritableByteStream ) {
461
464
stream <<< UInt8 ( ascii: " \" " )
462
465
stream. writeJSONEscaped ( value)
463
466
stream <<< UInt8 ( ascii: " \" " )
@@ -477,7 +480,7 @@ public struct Format {
477
480
private struct JSONEscapedStringListStreamable : ByteStreamable {
478
481
let items : [ String ]
479
482
480
- func write( to stream: OutputByteStream ) {
483
+ func write( to stream: WritableByteStream ) {
481
484
stream <<< UInt8 ( ascii: " [ " )
482
485
for (i, item) in items. enumerated ( ) {
483
486
if i != 0 { stream <<< " , " }
@@ -494,7 +497,7 @@ public struct Format {
494
497
private struct JSONEscapedDictionaryStreamable : ByteStreamable {
495
498
let items : [ String : String ]
496
499
497
- func write( to stream: OutputByteStream ) {
500
+ func write( to stream: WritableByteStream ) {
498
501
stream <<< UInt8 ( ascii: " { " )
499
502
for (offset: i, element: ( key: key, value: value) ) in items. enumerated ( ) {
500
503
if i != 0 { stream <<< " , " }
@@ -514,7 +517,7 @@ public struct Format {
514
517
let items : [ T ]
515
518
let transform : ( T ) -> String
516
519
517
- func write( to stream: OutputByteStream ) {
520
+ func write( to stream: WritableByteStream ) {
518
521
stream <<< UInt8 ( ascii: " [ " )
519
522
for (i, item) in items. enumerated ( ) {
520
523
if i != 0 { stream <<< " , " }
@@ -532,7 +535,7 @@ public struct Format {
532
535
let items : [ T ]
533
536
let separator : String
534
537
535
- func write( to stream: OutputByteStream ) {
538
+ func write( to stream: WritableByteStream ) {
536
539
for (i, item) in items. enumerated ( ) {
537
540
// Add the separator, if necessary.
538
541
if i != 0 {
@@ -558,7 +561,7 @@ public struct Format {
558
561
let transform : ( T ) -> ByteStreamable
559
562
let separator : String
560
563
561
- func write( to stream: OutputByteStream ) {
564
+ func write( to stream: WritableByteStream ) {
562
565
for (i, item) in items. enumerated ( ) {
563
566
if i != 0 { stream <<< separator }
564
567
stream <<< transform ( item)
@@ -579,22 +582,22 @@ public struct Format {
579
582
self . count = count
580
583
}
581
584
582
- func write( to stream: OutputByteStream ) {
585
+ func write( to stream: WritableByteStream ) {
583
586
for _ in 0 ..< count {
584
587
stream <<< string
585
588
}
586
589
}
587
590
}
588
591
}
589
592
590
- /// In memory implementation of OutputByteStream .
591
- public final class BufferedOutputByteStream : _OutputByteStreamBase {
593
+ /// In memory implementation of WritableByteStream .
594
+ public final class BufferedOutputByteStream : _WritableByteStreamBase {
592
595
593
596
/// Contents of the stream.
594
597
private var contents = [ UInt8] ( )
595
598
596
599
public init ( ) {
597
- // We disable the buffering of the underlying _OutputByteStreamBase as
600
+ // We disable the buffering of the underlying _WritableByteStreamBase as
598
601
// we are explicitly buffering the whole stream in memory
599
602
super. init ( buffered: false )
600
603
}
@@ -625,7 +628,7 @@ public final class BufferedOutputByteStream: _OutputByteStreamBase {
625
628
}
626
629
627
630
/// Represents a stream which is backed to a file. Not for instantiating.
628
- public class FileOutputByteStream : _OutputByteStreamBase {
631
+ public class FileOutputByteStream : _WritableByteStreamBase {
629
632
630
633
/// Closes the file flushing any buffered data.
631
634
public final func close( ) throws {
0 commit comments