Open the named file for writing, and return a new output channel on that file, positioned at the beginning of the file. The file is truncated to zero length if it already exists. It is created if it does not already exists.
Same as open_bin, but the file is opened in text mode, so that newline translation takes place during writes. On operating systems that do not distinguish between text mode and binary mode, this function behaves like open_bin.
open_gen mode perm filename opens the named file for writing, as described above. The extra argument mode specifies the opening mode. The extra argument perm specifies the file permissions, in case the file must be created. open_text and open_bin are special cases of this function.
with_open_bin fn f opens a channel oc on file fn and returns f
oc. After f returns, either with a value or by raising an exception, oc is guaranteed to be closed.
Close the given channel, flushing all buffered write operations. Output functions raise a Sys_error exception when they are applied to a closed output channel, except close and flush, which do nothing when applied to an already closed channel. Note that close may raise Sys_error if the operating system signals an error when flushing or closing.
Flush the buffer associated with the given output channel, performing all pending writes on that channel. Interactive programs must be careful about flushing standard output and standard error at the right time.
seek chan pos sets the current writing position to pos for channel chan. This works only for regular files. On files of other kinds (such as terminals, pipes and sockets), the behavior is unspecified.
Return the current writing position for the given channel. Does not work on channels opened with the Open_append flag (returns unspecified results).
For files opened in text mode under Windows, the returned position is approximate (owing to end-of-line conversion); in particular, saving the current position with pos, then going back to this position using seek will not work. For this programming idiom to work reliably and portably, the file must be opened in binary mode.
Return the size (number of characters) of the regular file on which the given channel is opened. If the channel is opened on a file that is not a regular file, the result is meaningless.
set_binary_mode oc true sets the channel oc to binary mode: no translations take place during output.
set_binary_mode oc false sets the channel oc to text mode: depending on the operating system, some translations may take place during output. For instance, under Windows, end-of-lines will be translated from \n to \r\n.
This function has no effect under operating systems that do not distinguish between text mode and binary mode.
set_buffered oc true sets the channel oc to buffered mode. In this mode, data output on oc will be buffered until either the internal buffer is full or the function flush or flush_all is called, at which point it will be sent to the output device.
set_buffered oc false sets the channel oc to unbuffered mode. In this mode, data output on oc will be sent to the output device immediately.
All channels are open in buffered mode by default.