@@ -18,7 +18,7 @@ private func hexdigit(_ value: UInt8) -> UInt8 {
1818
1919/// Describes a type which can be written to a byte stream.
2020public protocol ByteStreamable {
21- func write( to stream: OutputByteStream )
21+ func write( to stream: WritableByteStream )
2222}
2323
2424/// An output byte stream.
@@ -43,7 +43,7 @@ public protocol ByteStreamable {
4343///
4444/// would write each item in the list to the stream, separating them with a
4545/// space.
46- public protocol OutputByteStream : class , TextOutputStream {
46+ public protocol WritableByteStream : class , TextOutputStream {
4747 /// The current offset within the output stream.
4848 var position : Int { get }
4949
@@ -57,7 +57,10 @@ public protocol OutputByteStream: class, TextOutputStream {
5757 func flush( )
5858}
5959
60- extension OutputByteStream {
60+ // Public alias to the old name to not introduce API compatibility.
61+ public typealias OutputByteStream = WritableByteStream
62+
63+ extension WritableByteStream {
6164 /// Write a sequence of bytes to the buffer.
6265 public func write< S: Sequence > ( sequence: S ) where S. Iterator. Element == UInt8 {
6366 // Iterate the sequence and append byte by byte since sequence's append
@@ -124,12 +127,12 @@ extension OutputByteStream {
124127 }
125128}
126129
127- /// The `OutputByteStream ` base class.
130+ /// The `WritableByteStream ` base class.
128131///
129- /// This class provides a base and efficient implementation of the `OutputByteStream `
132+ /// This class provides a base and efficient implementation of the `WritableByteStream `
130133/// protocol. It can not be used as is-as subclasses as several functions need to be
131134/// implemented in subclasses.
132- public class _OutputByteStreamBase : OutputByteStream {
135+ public class _WritableByteStreamBase : WritableByteStream {
133136 /// If buffering is enabled
134137 @usableFromInline let _buffered : Bool
135138
@@ -149,7 +152,7 @@ public class _OutputByteStreamBase: OutputByteStream {
149152
150153 // When not buffered we still reserve 1 byte, as it is used by the
151154 // by the single byte write() variant.
152- self . _buffer. reserveCapacity ( buffered ? _OutputByteStreamBase . bufferSize : 1 )
155+ self . _buffer. reserveCapacity ( buffered ? _WritableByteStreamBase . bufferSize : 1 )
153156 }
154157
155158 // MARK: Data Access API
@@ -268,13 +271,13 @@ public class _OutputByteStreamBase: OutputByteStream {
268271
269272/// The thread-safe wrapper around output byte streams.
270273///
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 `,
273276/// it will also ensure it is type-safe will all other `ThreadSafeOutputByteStream` instances
274277/// around the same stream.
275- public final class ThreadSafeOutputByteStream : OutputByteStream {
278+ public final class ThreadSafeOutputByteStream : WritableByteStream {
276279 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
278281 private let queue : DispatchQueue
279282
280283 public var position : Int {
@@ -283,9 +286,9 @@ public final class ThreadSafeOutputByteStream: OutputByteStream {
283286 }
284287 }
285288
286- public init ( _ stream: OutputByteStream ) {
289+ public init ( _ stream: WritableByteStream ) {
287290 self . stream = stream
288- self . queue = ( stream as? _OutputByteStreamBase ) ? . queue ?? ThreadSafeOutputByteStream . defaultQueue
291+ self . queue = ( stream as? _WritableByteStreamBase ) ? . queue ?? ThreadSafeOutputByteStream . defaultQueue
289292 }
290293
291294 public func write( _ byte: UInt8 ) {
@@ -331,73 +334,73 @@ precedencegroup StreamingPrecedence {
331334// FIXME: This override shouldn't be necesary but removing it causes a 30% performance regression. This problem is
332335// tracked by the following bug: https://bugs.swift.org/browse/SR-8535
333336@discardableResult
334- public func <<< ( stream: OutputByteStream , value: ArraySlice < UInt8 > ) -> OutputByteStream {
337+ public func <<< ( stream: WritableByteStream , value: ArraySlice < UInt8 > ) -> WritableByteStream {
335338 value. write ( to: stream)
336339 return stream
337340}
338341
339342@discardableResult
340- public func <<< ( stream: OutputByteStream , value: ByteStreamable ) -> OutputByteStream {
343+ public func <<< ( stream: WritableByteStream , value: ByteStreamable ) -> WritableByteStream {
341344 value. write ( to: stream)
342345 return stream
343346}
344347
345348@discardableResult
346- public func <<< ( stream: OutputByteStream , value: CustomStringConvertible ) -> OutputByteStream {
349+ public func <<< ( stream: WritableByteStream , value: CustomStringConvertible ) -> WritableByteStream {
347350 value. description. write ( to: stream)
348351 return stream
349352}
350353
351354@discardableResult
352- public func <<< ( stream: OutputByteStream , value: ByteStreamable & CustomStringConvertible ) -> OutputByteStream {
355+ public func <<< ( stream: WritableByteStream , value: ByteStreamable & CustomStringConvertible ) -> WritableByteStream {
353356 value. write ( to: stream)
354357 return stream
355358}
356359
357360extension UInt8 : ByteStreamable {
358- public func write( to stream: OutputByteStream ) {
361+ public func write( to stream: WritableByteStream ) {
359362 stream. write ( self )
360363 }
361364}
362365
363366extension Character : ByteStreamable {
364- public func write( to stream: OutputByteStream ) {
367+ public func write( to stream: WritableByteStream ) {
365368 stream. write ( String ( self ) )
366369 }
367370}
368371
369372extension String : ByteStreamable {
370- public func write( to stream: OutputByteStream ) {
373+ public func write( to stream: WritableByteStream ) {
371374 stream. write ( self . utf8)
372375 }
373376}
374377
375378extension Substring : ByteStreamable {
376- public func write( to stream: OutputByteStream ) {
379+ public func write( to stream: WritableByteStream ) {
377380 stream. write ( self . utf8)
378381 }
379382}
380383
381384extension StaticString : ByteStreamable {
382- public func write( to stream: OutputByteStream ) {
385+ public func write( to stream: WritableByteStream ) {
383386 withUTF8Buffer { stream. write ( $0) }
384387 }
385388}
386389
387390extension Array : ByteStreamable where Element == UInt8 {
388- public func write( to stream: OutputByteStream ) {
391+ public func write( to stream: WritableByteStream ) {
389392 stream. write ( self )
390393 }
391394}
392395
393396extension ArraySlice : ByteStreamable where Element == UInt8 {
394- public func write( to stream: OutputByteStream ) {
397+ public func write( to stream: WritableByteStream ) {
395398 stream. write ( self )
396399 }
397400}
398401
399402extension ContiguousArray : ByteStreamable where Element == UInt8 {
400- public func write( to stream: OutputByteStream ) {
403+ public func write( to stream: WritableByteStream ) {
401404 stream. write ( self )
402405 }
403406}
@@ -413,7 +416,7 @@ public struct Format {
413416 private struct JSONEscapedBoolStreamable : ByteStreamable {
414417 let value : Bool
415418
416- func write( to stream: OutputByteStream ) {
419+ func write( to stream: WritableByteStream ) {
417420 stream <<< ( value ? " true " : " false " )
418421 }
419422 }
@@ -425,7 +428,7 @@ public struct Format {
425428 private struct JSONEscapedIntStreamable : ByteStreamable {
426429 let value : Int
427430
428- func write( to stream: OutputByteStream ) {
431+ func write( to stream: WritableByteStream ) {
429432 // FIXME: Diagnose integers which cannot be represented in JSON.
430433 stream <<< value. description
431434 }
@@ -438,7 +441,7 @@ public struct Format {
438441 private struct JSONEscapedDoubleStreamable : ByteStreamable {
439442 let value : Double
440443
441- func write( to stream: OutputByteStream ) {
444+ func write( to stream: WritableByteStream ) {
442445 // FIXME: What should we do about NaN, etc.?
443446 //
444447 // FIXME: Is Double.debugDescription the best representation?
@@ -457,7 +460,7 @@ public struct Format {
457460 private struct JSONEscapedStringStreamable : ByteStreamable {
458461 let value : String
459462
460- func write( to stream: OutputByteStream ) {
463+ func write( to stream: WritableByteStream ) {
461464 stream <<< UInt8 ( ascii: " \" " )
462465 stream. writeJSONEscaped ( value)
463466 stream <<< UInt8 ( ascii: " \" " )
@@ -477,7 +480,7 @@ public struct Format {
477480 private struct JSONEscapedStringListStreamable : ByteStreamable {
478481 let items : [ String ]
479482
480- func write( to stream: OutputByteStream ) {
483+ func write( to stream: WritableByteStream ) {
481484 stream <<< UInt8 ( ascii: " [ " )
482485 for (i, item) in items. enumerated ( ) {
483486 if i != 0 { stream <<< " , " }
@@ -494,7 +497,7 @@ public struct Format {
494497 private struct JSONEscapedDictionaryStreamable : ByteStreamable {
495498 let items : [ String : String ]
496499
497- func write( to stream: OutputByteStream ) {
500+ func write( to stream: WritableByteStream ) {
498501 stream <<< UInt8 ( ascii: " { " )
499502 for (offset: i, element: ( key: key, value: value) ) in items. enumerated ( ) {
500503 if i != 0 { stream <<< " , " }
@@ -514,7 +517,7 @@ public struct Format {
514517 let items : [ T ]
515518 let transform : ( T ) -> String
516519
517- func write( to stream: OutputByteStream ) {
520+ func write( to stream: WritableByteStream ) {
518521 stream <<< UInt8 ( ascii: " [ " )
519522 for (i, item) in items. enumerated ( ) {
520523 if i != 0 { stream <<< " , " }
@@ -532,7 +535,7 @@ public struct Format {
532535 let items : [ T ]
533536 let separator : String
534537
535- func write( to stream: OutputByteStream ) {
538+ func write( to stream: WritableByteStream ) {
536539 for (i, item) in items. enumerated ( ) {
537540 // Add the separator, if necessary.
538541 if i != 0 {
@@ -558,7 +561,7 @@ public struct Format {
558561 let transform : ( T ) -> ByteStreamable
559562 let separator : String
560563
561- func write( to stream: OutputByteStream ) {
564+ func write( to stream: WritableByteStream ) {
562565 for (i, item) in items. enumerated ( ) {
563566 if i != 0 { stream <<< separator }
564567 stream <<< transform ( item)
@@ -579,22 +582,22 @@ public struct Format {
579582 self . count = count
580583 }
581584
582- func write( to stream: OutputByteStream ) {
585+ func write( to stream: WritableByteStream ) {
583586 for _ in 0 ..< count {
584587 stream <<< string
585588 }
586589 }
587590 }
588591}
589592
590- /// In memory implementation of OutputByteStream .
591- public final class BufferedOutputByteStream : _OutputByteStreamBase {
593+ /// In memory implementation of WritableByteStream .
594+ public final class BufferedOutputByteStream : _WritableByteStreamBase {
592595
593596 /// Contents of the stream.
594597 private var contents = [ UInt8] ( )
595598
596599 public init ( ) {
597- // We disable the buffering of the underlying _OutputByteStreamBase as
600+ // We disable the buffering of the underlying _WritableByteStreamBase as
598601 // we are explicitly buffering the whole stream in memory
599602 super. init ( buffered: false )
600603 }
@@ -625,7 +628,7 @@ public final class BufferedOutputByteStream: _OutputByteStreamBase {
625628}
626629
627630/// Represents a stream which is backed to a file. Not for instantiating.
628- public class FileOutputByteStream : _OutputByteStreamBase {
631+ public class FileOutputByteStream : _WritableByteStreamBase {
629632
630633 /// Closes the file flushing any buffered data.
631634 public final func close( ) throws {
0 commit comments