Jon Bailey
02/03/2023, 1:28 PMclient.prepareRequest(request).execute {
val byteBufferSize = 1024 * 100
val fileHandle = NSFileHandle.fileHandleForWritingAtPath(file)!!
val channel = it.bodyAsChannel()
while (!channel.isClosedForRead) {
val packet = channel.readRemaining(byteBufferSize.toLong())
while (!packet.isEmpty) {
val bytes = packet.readBytes()
bytes.usePinned {
val data = NSData.dataWithBytesNoCopy(it.addressOf(0), it.get().size.toULong(), freeWhenDone = false)
fileHandle.writeData(data)
}
}
}
fileHandle.closeFile()
}
Is there something I'm missing to write a large file directly from the network to disk without high memory usage?ribesg
02/03/2023, 1:33 PMJon Bailey
02/03/2023, 2:32 PM