mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
23 lines
675 B
Swift
23 lines
675 B
Swift
import Foundation
|
|
|
|
internal extension Data {
|
|
|
|
init(from inputStream: InputStream) throws {
|
|
self.init()
|
|
inputStream.open()
|
|
defer { inputStream.close() }
|
|
let bufferSize = 1024
|
|
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize)
|
|
defer { buffer.deallocate() }
|
|
while inputStream.hasBytesAvailable {
|
|
let count = inputStream.read(buffer, maxLength: bufferSize)
|
|
if count < 0 {
|
|
throw inputStream.streamError!
|
|
} else if count == 0 {
|
|
break
|
|
} else {
|
|
append(buffer, count: count)
|
|
}
|
|
}
|
|
}
|
|
}
|