Are Open OutputStreams Buffered or Unbuffered?

I am working on an app that is streaming data from a bluetooth device to an iPhone. As data constantly arrives to the phone, I am repeatedly decoding data segments and sending it to a file through a OutputStream (from Foundation).

Trying to streamline this background work, I want to make sure the data I/O is using a buffered write. Looking over documentation for the OutputStream class, I cannot find any mention of how to flush the buffer if needed, and am unsure if the Stream object is using a buffer across my repeated calls.

Are OutputStreams sending binary data to a file buffered or unbuffered?

Thank you in advance for clarifying this mechanic!

I am using XCode Version 15.3, and Swift 5.10

Answered by DTS Engineer in 788222022

Foundation’s stream types are a class cluster, and it’s up to each concrete class as to whether it’s buffered or not. The file streams are not buffered.

The above is also true for FileHandle.

You could implement your own buffering layer on top of Outputstream but, when I find myself in this situation, I generally use C’s stdio library.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Foundation’s stream types are a class cluster, and it’s up to each concrete class as to whether it’s buffered or not. The file streams are not buffered.

The above is also true for FileHandle.

You could implement your own buffering layer on top of Outputstream but, when I find myself in this situation, I generally use C’s stdio library.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Are Open OutputStreams Buffered or Unbuffered?
 
 
Q