-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
| Previous ID | SR-3901 |
| Radar | None |
| Original Reporter | kelko (JIRA User) |
| Type | Improvement |
Attachment: Download
Additional Detail from JIRA
| Votes | 1 |
| Component/s | Foundation, Standard Library |
| Labels | Improvement, LanguageFeatureRequest |
| Assignee | None |
| Priority | Medium |
md5: d78492d6b6817bd309d8e3ab74f9e649
Issue Description:
For me it seems, that the classes for handling IO in/from files are inconsistent to each other.
On the one hand there is InputStream, subclassing Stream, and main API like:
func read(_ buffer: UnsafeMutablePointer<UInt8>, maxLength len: Int) -> Int
func getBuffer(_ buffer: UnsafeMutablePointer<UnsafeMutablePointer<UInt8>?>, length len: UnsafeMutablePointer<Int>) -> Bool
var hasBytesAvailable: Bool { get }On the other hand there is FileHandle with an API for reading like
var availableData: Data { get }
func readDataToEndOfFile() -> Data
func readData(ofLength length: Int) -> DataFor writing there is same FileHandle with writeData, but also OutputStream. To add to the confusion there is also TextOutputStream which does not seem to be an extension of OutputStream - although the name might suggest otherwise.
And why is there no TextInputStream?
It really makes it hard to unify handling of different input types (FileHandle has built-in support for Console, InputStream can be used to read from an URL or an Data object., Why is there no TextInputStream to read from a String?) and output types.
No matter which class I end up using it always feels like I might be making the wrong choice and cut myself off of yet unseen new features.