mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-17 08:06:43 -05:00
3 lines
No EOL
19 KiB
HTML
3 lines
No EOL
19 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Out_channel (ocaml.Stdlib.Out_channel)</title><link rel="stylesheet" href="../../../_odoc-theme/odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 2.2.1"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a> – <a href="../../index.html">ocaml</a> » <a href="../index.html">Stdlib</a> » Out_channel</nav><header class="odoc-preamble"><h1>Module <code><span>Stdlib.Out_channel</span></code></h1><p>Output channels.</p><ul class="at-tags"><li class="since"><span class="at-tag">since</span> 4.14.0</li></ul></header><div class="odoc-content"><div class="odoc-spec"><div class="spec type anchored" id="type-t"><a href="#type-t" class="anchor"></a><code><span><span class="keyword">type</span> t</span><span> = <a href="../index.html#type-out_channel">out_channel</a></span></code></div><div class="spec-doc"><p>The type of output channel.</p></div></div><div class="odoc-spec"><div class="spec type anchored" id="type-open_flag"><a href="#type-open_flag" class="anchor"></a><code><span><span class="keyword">type</span> open_flag</span><span> = <a href="../index.html#type-open_flag">open_flag</a></span><span> = </span></code><ol><li id="type-open_flag.Open_rdonly" class="def variant constructor anchored"><a href="#type-open_flag.Open_rdonly" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_rdonly</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>open for reading.</p><span class="comment-delim">*)</span></div></li><li id="type-open_flag.Open_wronly" class="def variant constructor anchored"><a href="#type-open_flag.Open_wronly" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_wronly</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>open for writing.</p><span class="comment-delim">*)</span></div></li><li id="type-open_flag.Open_append" class="def variant constructor anchored"><a href="#type-open_flag.Open_append" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_append</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>open for appending: always write at end of file.</p><span class="comment-delim">*)</span></div></li><li id="type-open_flag.Open_creat" class="def variant constructor anchored"><a href="#type-open_flag.Open_creat" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_creat</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>create the file if it does not exist.</p><span class="comment-delim">*)</span></div></li><li id="type-open_flag.Open_trunc" class="def variant constructor anchored"><a href="#type-open_flag.Open_trunc" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_trunc</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>empty the file if it already exists.</p><span class="comment-delim">*)</span></div></li><li id="type-open_flag.Open_excl" class="def variant constructor anchored"><a href="#type-open_flag.Open_excl" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_excl</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>fail if Open_creat and the file already exists.</p><span class="comment-delim">*)</span></div></li><li id="type-open_flag.Open_binary" class="def variant constructor anchored"><a href="#type-open_flag.Open_binary" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_binary</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>open in binary mode (no conversion).</p><span class="comment-delim">*)</span></div></li><li id="type-open_flag.Open_text" class="def variant constructor anchored"><a href="#type-open_flag.Open_text" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_text</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>open in text mode (may perform conversions).</p><span class="comment-delim">*)</span></div></li><li id="type-open_flag.Open_nonblock" class="def variant constructor anchored"><a href="#type-open_flag.Open_nonblock" class="anchor"></a><code><span>| </span><span><span class="constructor">Open_nonblock</span></span></code><div class="def-doc"><span class="comment-delim">(*</span><p>open in non-blocking mode.</p><span class="comment-delim">*)</span></div></li></ol></div><div class="spec-doc"><p>Opening modes for <a href="#val-open_gen"><code>open_gen</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-stdout"><a href="#val-stdout" class="anchor"></a><code><span><span class="keyword">val</span> stdout : <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>The standard output for the process.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-stderr"><a href="#val-stderr" class="anchor"></a><code><span><span class="keyword">val</span> stderr : <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>The standard error output for the process.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-open_bin"><a href="#val-open_bin" class="anchor"></a><code><span><span class="keyword">val</span> open_bin : <span>string <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>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.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-open_text"><a href="#val-open_text" class="anchor"></a><code><span><span class="keyword">val</span> open_text : <span>string <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p>Same as <a href="#val-open_bin"><code>open_bin</code></a>, 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 <a href="#val-open_bin"><code>open_bin</code></a>.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-open_gen"><a href="#val-open_gen" class="anchor"></a><code><span><span class="keyword">val</span> open_gen : <span><span><a href="#type-open_flag">open_flag</a> list</span> <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> <a href="#type-t">t</a></span></code></div><div class="spec-doc"><p><code>open_gen mode perm filename</code> opens the named file for writing, as described above. The extra argument <code>mode</code> specifies the opening mode. The extra argument <code>perm</code> specifies the file permissions, in case the file must be created. <a href="#val-open_text"><code>open_text</code></a> and <a href="#val-open_bin"><code>open_bin</code></a> are special cases of this function.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-with_open_bin"><a href="#val-with_open_bin" class="anchor"></a><code><span><span class="keyword">val</span> with_open_bin : <span>string <span class="arrow">-></span></span> <span><span>(<span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span class="type-var">'a</span>)</span> <span class="arrow">-></span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p><code>with_open_bin fn f</code> opens a channel <code>oc</code> on file <code>fn</code> and returns <code>f
|
||
oc</code>. After <code>f</code> returns, either with a value or by raising an exception, <code>oc</code> is guaranteed to be closed.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-with_open_text"><a href="#val-with_open_text" class="anchor"></a><code><span><span class="keyword">val</span> with_open_text : <span>string <span class="arrow">-></span></span> <span><span>(<span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span class="type-var">'a</span>)</span> <span class="arrow">-></span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Like <a href="#val-with_open_bin"><code>with_open_bin</code></a>, but the channel is opened in text mode (see <a href="#val-open_text"><code>open_text</code></a>).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-with_open_gen"><a href="#val-with_open_gen" class="anchor"></a><code><span><span class="keyword">val</span> with_open_gen : <span><span><a href="#type-open_flag">open_flag</a> list</span> <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> <span><span>(<span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span class="type-var">'a</span>)</span> <span class="arrow">-></span></span> <span class="type-var">'a</span></span></code></div><div class="spec-doc"><p>Like <a href="#val-with_open_bin"><code>with_open_bin</code></a>, but can specify the opening mode and file permission, in case the file must be created (see <a href="#val-open_gen"><code>open_gen</code></a>).</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-seek"><a href="#val-seek" class="anchor"></a><code><span><span class="keyword">val</span> seek : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>int64 <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>seek chan pos</code> sets the current writing position to <code>pos</code> for channel <code>chan</code>. This works only for regular files. On files of other kinds (such as terminals, pipes and sockets), the behavior is unspecified.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-pos"><a href="#val-pos" class="anchor"></a><code><span><span class="keyword">val</span> pos : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> int64</span></code></div><div class="spec-doc"><p>Return the current writing position for the given channel. Does not work on channels opened with the <code>Open_append</code> flag (returns unspecified results).</p><p>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 <a href="#val-pos"><code>pos</code></a>, then going back to this position using <a href="#val-seek"><code>seek</code></a> will not work. For this programming idiom to work reliably and portably, the file must be opened in binary mode.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-length"><a href="#val-length" class="anchor"></a><code><span><span class="keyword">val</span> length : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> int64</span></code></div><div class="spec-doc"><p>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.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-close"><a href="#val-close" class="anchor"></a><code><span><span class="keyword">val</span> close : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Close the given channel, flushing all buffered write operations. Output functions raise a <code>Sys_error</code> exception when they are applied to a closed output channel, except <a href="#val-close"><code>close</code></a> and <a href="#val-flush"><code>flush</code></a>, which do nothing when applied to an already closed channel. Note that <a href="#val-close"><code>close</code></a> may raise <code>Sys_error</code> if the operating system signals an error when flushing or closing.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-close_noerr"><a href="#val-close_noerr" class="anchor"></a><code><span><span class="keyword">val</span> close_noerr : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Same as <a href="#val-close"><code>close</code></a>, but ignore all errors.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-flush"><a href="#val-flush" class="anchor"></a><code><span><span class="keyword">val</span> flush : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>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.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-flush_all"><a href="#val-flush_all" class="anchor"></a><code><span><span class="keyword">val</span> flush_all : <span>unit <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Flush all open output channels; ignore errors.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-output_char"><a href="#val-output_char" class="anchor"></a><code><span><span class="keyword">val</span> output_char : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>char <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Write the character on the given output channel.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-output_byte"><a href="#val-output_byte" class="anchor"></a><code><span><span class="keyword">val</span> output_byte : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Write one 8-bit integer (as the single character with that code) on the given output channel. The given integer is taken modulo 256.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-output_string"><a href="#val-output_string" class="anchor"></a><code><span><span class="keyword">val</span> output_string : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Write the string on the given output channel.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-output_bytes"><a href="#val-output_bytes" class="anchor"></a><code><span><span class="keyword">val</span> output_bytes : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>bytes <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Write the byte sequence on the given output channel.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-output"><a href="#val-output" class="anchor"></a><code><span><span class="keyword">val</span> output : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>bytes <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>output oc buf pos len</code> writes <code>len</code> characters from byte sequence <code>buf</code>, starting at offset <code>pos</code>, to the given output channel <code>oc</code>.</p><ul class="at-tags"><li class="raises"><span class="at-tag">raises</span> <span class="value">Invalid_argument</span> <p>if <code>pos</code> and <code>len</code> do not designate a valid range of <code>buf</code>.</p></li></ul></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-output_substring"><a href="#val-output_substring" class="anchor"></a><code><span><span class="keyword">val</span> output_substring : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>string <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> <span>int <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p>Same as <a href="#val-output"><code>output</code></a> but take a string as argument instead of a byte sequence.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set_binary_mode"><a href="#val-set_binary_mode" class="anchor"></a><code><span><span class="keyword">val</span> set_binary_mode : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>bool <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>set_binary_mode oc true</code> sets the channel <code>oc</code> to binary mode: no translations take place during output.</p><p><code>set_binary_mode oc false</code> sets the channel <code>oc</code> 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 <code>\n</code> to <code>\r\n</code>.</p><p>This function has no effect under operating systems that do not distinguish between text mode and binary mode.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-set_buffered"><a href="#val-set_buffered" class="anchor"></a><code><span><span class="keyword">val</span> set_buffered : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> <span>bool <span class="arrow">-></span></span> unit</span></code></div><div class="spec-doc"><p><code>set_buffered oc true</code> sets the channel <code>oc</code> to <em>buffered</em> mode. In this mode, data output on <code>oc</code> will be buffered until either the internal buffer is full or the function <a href="#val-flush"><code>flush</code></a> or <a href="#val-flush_all"><code>flush_all</code></a> is called, at which point it will be sent to the output device.</p><p><code>set_buffered oc false</code> sets the channel <code>oc</code> to <em>unbuffered</em> mode. In this mode, data output on <code>oc</code> will be sent to the output device immediately.</p><p>All channels are open in <em>buffered</em> mode by default.</p></div></div><div class="odoc-spec"><div class="spec value anchored" id="val-is_buffered"><a href="#val-is_buffered" class="anchor"></a><code><span><span class="keyword">val</span> is_buffered : <span><a href="#type-t">t</a> <span class="arrow">-></span></span> bool</span></code></div><div class="spec-doc"><p><code>is_buffered oc</code> returns whether the channel <code>oc</code> is buffered (see <a href="#val-set_buffered"><code>set_buffered</code></a>).</p></div></div></div></body></html> |