I had a look at the docs but I can't seem to find the relevant part. Can anyone tell me what the call to sync
is for in the following code?
fh = Tempfile.new('tmp')
fh.sync = true
It sets the sync mode of the file.
This affects future operations and causes output to be written without block buffering.
If f.tty?
is true, that is, if the file is connected to a console-like device, then output is not block buffered. But when output goes to a pipe or file, f.tty?
will be false and the I/O library will switch to block buffering, that is, accumulating output in a buffer and writing it only if the file is closed, the program exits, or the buffer fills up. This is faster and the end result is the same.
Setting f.sync = true
defeats this switch. This can be useful if the output of the pipe is connected to something that actually is a console or in some way interactive or if the contents of the file are being actively monitored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With