I have the following code:
extension FileHandle {
func readInto(_ buffer: inout [UInt8]) -> Int {
buffer.withUnsafeMutableBytes {
Darwin.read(fileDescriptor, $0.baseAddress, $0.count)
}
}
}
It can compile, but I wonder if this is supported since it's code in an app that is going to be submitted to App Store.
The reason I don't use read(upToCount:)
or readData(ofLength:)
is that I am reading possibly very large files by small chunks and don't want to let Swift runtime allocate small buffers repeatedly.