mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
208 lines
No EOL
14 KiB
HTML
208 lines
No EOL
14 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="style.css" type="text/css">
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="Start" href="index.html">
|
|
<link rel="previous" href="Containers.Int64.html">
|
|
<link rel="next" href="Containers.Hashtbl.html">
|
|
<link rel="Up" href="Containers.html">
|
|
<link title="Index of types" rel=Appendix href="index_types.html">
|
|
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
|
|
<link title="Index of values" rel=Appendix href="index_values.html">
|
|
<link title="Index of class methods" rel=Appendix href="index_methods.html">
|
|
<link title="Index of class types" rel=Appendix href="index_class_types.html">
|
|
<link title="Index of modules" rel=Appendix href="index_modules.html">
|
|
<link title="Index of module types" rel=Appendix href="index_module_types.html">
|
|
<link title="CCVector" rel="Chapter" href="CCVector.html">
|
|
<link title="CCHeap" rel="Chapter" href="CCHeap.html">
|
|
<link title="CCList" rel="Chapter" href="CCList.html">
|
|
<link title="CCOpt" rel="Chapter" href="CCOpt.html">
|
|
<link title="CCPair" rel="Chapter" href="CCPair.html">
|
|
<link title="CCFun" rel="Chapter" href="CCFun.html">
|
|
<link title="CCHash" rel="Chapter" href="CCHash.html">
|
|
<link title="CCInt" rel="Chapter" href="CCInt.html">
|
|
<link title="CCBool" rel="Chapter" href="CCBool.html">
|
|
<link title="CCFloat" rel="Chapter" href="CCFloat.html">
|
|
<link title="CCArray" rel="Chapter" href="CCArray.html">
|
|
<link title="CCRef" rel="Chapter" href="CCRef.html">
|
|
<link title="CCSet" rel="Chapter" href="CCSet.html">
|
|
<link title="CCOrd" rel="Chapter" href="CCOrd.html">
|
|
<link title="CCRandom" rel="Chapter" href="CCRandom.html">
|
|
<link title="CCString" rel="Chapter" href="CCString.html">
|
|
<link title="CCHashtbl" rel="Chapter" href="CCHashtbl.html">
|
|
<link title="CCMap" rel="Chapter" href="CCMap.html">
|
|
<link title="CCFormat" rel="Chapter" href="CCFormat.html">
|
|
<link title="CCIO" rel="Chapter" href="CCIO.html">
|
|
<link title="CCInt64" rel="Chapter" href="CCInt64.html">
|
|
<link title="CCChar" rel="Chapter" href="CCChar.html">
|
|
<link title="CCResult" rel="Chapter" href="CCResult.html">
|
|
<link title="CCParse" rel="Chapter" href="CCParse.html">
|
|
<link title="CCArray_slice" rel="Chapter" href="CCArray_slice.html">
|
|
<link title="CCListLabels" rel="Chapter" href="CCListLabels.html">
|
|
<link title="CCArrayLabels" rel="Chapter" href="CCArrayLabels.html">
|
|
<link title="CCEqual" rel="Chapter" href="CCEqual.html">
|
|
<link title="Containers" rel="Chapter" href="Containers.html">
|
|
<link title="CCKTree" rel="Chapter" href="CCKTree.html">
|
|
<link title="CCKList" rel="Chapter" href="CCKList.html">
|
|
<link title="CCLazy_list" rel="Chapter" href="CCLazy_list.html">
|
|
<link title="CCMultiMap" rel="Chapter" href="CCMultiMap.html">
|
|
<link title="CCMultiSet" rel="Chapter" href="CCMultiSet.html">
|
|
<link title="CCTrie" rel="Chapter" href="CCTrie.html">
|
|
<link title="CCFlatHashtbl" rel="Chapter" href="CCFlatHashtbl.html">
|
|
<link title="CCCache" rel="Chapter" href="CCCache.html">
|
|
<link title="CCPersistentHashtbl" rel="Chapter" href="CCPersistentHashtbl.html">
|
|
<link title="CCDeque" rel="Chapter" href="CCDeque.html">
|
|
<link title="CCFQueue" rel="Chapter" href="CCFQueue.html">
|
|
<link title="CCBV" rel="Chapter" href="CCBV.html">
|
|
<link title="CCMixtbl" rel="Chapter" href="CCMixtbl.html">
|
|
<link title="CCMixmap" rel="Chapter" href="CCMixmap.html">
|
|
<link title="CCRingBuffer" rel="Chapter" href="CCRingBuffer.html">
|
|
<link title="CCIntMap" rel="Chapter" href="CCIntMap.html">
|
|
<link title="CCPersistentArray" rel="Chapter" href="CCPersistentArray.html">
|
|
<link title="CCMixset" rel="Chapter" href="CCMixset.html">
|
|
<link title="CCGraph" rel="Chapter" href="CCGraph.html">
|
|
<link title="CCHashSet" rel="Chapter" href="CCHashSet.html">
|
|
<link title="CCBitField" rel="Chapter" href="CCBitField.html">
|
|
<link title="CCHashTrie" rel="Chapter" href="CCHashTrie.html">
|
|
<link title="CCWBTree" rel="Chapter" href="CCWBTree.html">
|
|
<link title="CCRAL" rel="Chapter" href="CCRAL.html">
|
|
<link title="CCSimple_queue" rel="Chapter" href="CCSimple_queue.html">
|
|
<link title="CCImmutArray" rel="Chapter" href="CCImmutArray.html">
|
|
<link title="CCHet" rel="Chapter" href="CCHet.html">
|
|
<link title="CCZipper" rel="Chapter" href="CCZipper.html">
|
|
<link title="CCPool" rel="Chapter" href="CCPool.html">
|
|
<link title="CCLock" rel="Chapter" href="CCLock.html">
|
|
<link title="CCSemaphore" rel="Chapter" href="CCSemaphore.html">
|
|
<link title="CCThread" rel="Chapter" href="CCThread.html">
|
|
<link title="CCBlockingQueue" rel="Chapter" href="CCBlockingQueue.html">
|
|
<link title="CCTimer" rel="Chapter" href="CCTimer.html">
|
|
<link title="CCUnix" rel="Chapter" href="CCUnix.html">
|
|
<link title="CCSexp" rel="Chapter" href="CCSexp.html">
|
|
<link title="CCSexp_lex" rel="Chapter" href="CCSexp_lex.html"><link title="Input" rel="Section" href="#2_Input">
|
|
<link title="Output" rel="Section" href="#2_Output">
|
|
<link title="Both" rel="Section" href="#2_Both">
|
|
<link title="Misc for Generators" rel="Section" href="#2_MiscforGenerators">
|
|
<link title="File and file names" rel="Section" href="#2_Fileandfilenames">
|
|
<title>Containers doc : Containers.IO</title>
|
|
</head>
|
|
<body>
|
|
<div class="navbar"><a class="pre" href="Containers.Int64.html" title="Containers.Int64">Previous</a>
|
|
<a class="up" href="Containers.html" title="Containers">Up</a>
|
|
<a class="post" href="Containers.Hashtbl.html" title="Containers.Hashtbl">Next</a>
|
|
</div>
|
|
<h1>Module <a href="type_Containers.IO.html">Containers.IO</a></h1>
|
|
|
|
<pre><span class="keyword">module</span> IO: <code class="type"><a href="CCIO.html">CCIO</a></code></pre><hr width="100%">
|
|
|
|
<pre><span id="TYPEor_error"><span class="keyword">type</span> <code class="type">'a</code> or_error</span> = <code class="type">('a, string) Result.result</code> </pre>
|
|
|
|
|
|
<pre><span id="TYPEgen"><span class="keyword">type</span> <code class="type">'a</code> gen</span> = <code class="type">unit -> 'a option</code> </pre>
|
|
<div class="info ">
|
|
See <code class="code"><span class="constructor">Gen</span></code> in the gen library<br>
|
|
</div>
|
|
|
|
<br>
|
|
<h2 id="2_Input">Input</h2><br>
|
|
|
|
<pre><span id="VALwith_in"><span class="keyword">val</span> with_in</span> : <code class="type">?mode:int -><br> ?flags:Pervasives.open_flag list -><br> string -> (Pervasives.in_channel -> 'a) -> 'a</code></pre><div class="info ">
|
|
Open an input file with the given optional flag list, calls the function
|
|
on the input channel. When the function raises or returns, the
|
|
channel is closed.<br>
|
|
<b>Raises</b> <code>Sys_error</code> in case of error (same as <code class="code">open_in</code> and <code class="code">close_in</code>)<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">flags</code> : opening flags (default <code class="code">[<span class="constructor">Open_text</span>]</code>). <code class="code"><span class="constructor">Open_rdonly</span></code> is used in any cases</div>
|
|
|
|
<pre><span id="VALread_chunks"><span class="keyword">val</span> read_chunks</span> : <code class="type">?size:int -> Pervasives.in_channel -> string <a href="CCIO.html#TYPEgen">gen</a></code></pre><div class="info ">
|
|
Read the channel's content into chunks of size <code class="code">size</code><br>
|
|
</div>
|
|
|
|
<pre><span id="VALread_line"><span class="keyword">val</span> read_line</span> : <code class="type">Pervasives.in_channel -> string option</code></pre><div class="info ">
|
|
Read a line from the channel. Returns <code class="code"><span class="constructor">None</span></code> if the input is terminated.
|
|
The "\n" is removed from the line.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALread_lines"><span class="keyword">val</span> read_lines</span> : <code class="type">Pervasives.in_channel -> string <a href="CCIO.html#TYPEgen">gen</a></code></pre><div class="info ">
|
|
Read all lines. The generator should be traversed only once.<br>
|
|
</div>
|
|
|
|
<pre><span id="VALread_lines_l"><span class="keyword">val</span> read_lines_l</span> : <code class="type">Pervasives.in_channel -> string list</code></pre><div class="info ">
|
|
Read all lines into a list<br>
|
|
</div>
|
|
|
|
<pre><span id="VALread_all"><span class="keyword">val</span> read_all</span> : <code class="type">?size:int -> Pervasives.in_channel -> string</code></pre><div class="info ">
|
|
Read the whole channel into a buffer, then converted into a string.<br>
|
|
<b>Since</b> 0.7<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">size</code> : the internal buffer size</div>
|
|
|
|
<pre><span id="VALread_all_bytes"><span class="keyword">val</span> read_all_bytes</span> : <code class="type">?size:int -> Pervasives.in_channel -> Bytes.t</code></pre><div class="info ">
|
|
Read the whole channel into a mutable byte array<br>
|
|
<b>Since</b> 0.12<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">size</code> : the internal buffer size</div>
|
|
<br>
|
|
<h2 id="2_Output">Output</h2><br>
|
|
|
|
<pre><span id="VALwith_out"><span class="keyword">val</span> with_out</span> : <code class="type">?mode:int -><br> ?flags:Pervasives.open_flag list -><br> string -> (Pervasives.out_channel -> 'a) -> 'a</code></pre><div class="info ">
|
|
Same as <a href="CCIO.html#VALwith_in"><code class="code"><span class="constructor">CCIO</span>.with_in</code></a> but for an output channel<br>
|
|
<b>Raises</b> <code>Sys_error</code> in case of error (same as <code class="code">open_out</code> and <code class="code">close_out</code>)
|
|
<code class="code"><span class="constructor">Open_wronly</span></code> is used in any cases<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">flags</code> : opening flags (default <code class="code">[<span class="constructor">Open_creat</span>; <span class="constructor">Open_trunc</span>; <span class="constructor">Open_text</span>]</code>).</div>
|
|
|
|
<pre><span id="VALwith_out_a"><span class="keyword">val</span> with_out_a</span> : <code class="type">?mode:int -><br> ?flags:Pervasives.open_flag list -><br> string -> (Pervasives.out_channel -> 'a) -> 'a</code></pre><div class="info ">
|
|
Similar to <a href="CCIO.html#VALwith_out"><code class="code"><span class="constructor">CCIO</span>.with_out</code></a> but with the <code class="code">[<span class="constructor">Open_append</span>; <span class="constructor">Open_creat</span>; <span class="constructor">Open_wronly</span>]</code>
|
|
flags activated, to append to the file.<br>
|
|
<b>Raises</b> <code>Sys_error</code> in case of error (same as <code class="code">open_out</code> and <code class="code">close_out</code>)<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwrite_line"><span class="keyword">val</span> write_line</span> : <code class="type">Pervasives.out_channel -> string -> unit</code></pre><div class="info ">
|
|
Write the given string on the channel, followed by "\n"<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwrite_gen"><span class="keyword">val</span> write_gen</span> : <code class="type">?sep:string -> Pervasives.out_channel -> string <a href="CCIO.html#TYPEgen">gen</a> -> unit</code></pre><div class="info ">
|
|
Write the given strings on the output. If provided, add <code class="code">sep</code> between
|
|
every two strings (but not at the end)<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwrite_lines"><span class="keyword">val</span> write_lines</span> : <code class="type">Pervasives.out_channel -> string <a href="CCIO.html#TYPEgen">gen</a> -> unit</code></pre><div class="info ">
|
|
Write every string on the output, followed by "\n".<br>
|
|
</div>
|
|
|
|
<pre><span id="VALwrite_lines_l"><span class="keyword">val</span> write_lines_l</span> : <code class="type">Pervasives.out_channel -> string list -> unit</code></pre><br>
|
|
<h2 id="2_Both">Both</h2><br>
|
|
|
|
<pre><span id="VALwith_in_out"><span class="keyword">val</span> with_in_out</span> : <code class="type">?mode:int -><br> ?flags:Pervasives.open_flag list -><br> string -> (Pervasives.in_channel -> Pervasives.out_channel -> 'a) -> 'a</code></pre><div class="info ">
|
|
Combines <a href="CCIO.html#VALwith_in"><code class="code"><span class="constructor">CCIO</span>.with_in</code></a> and <a href="CCIO.html#VALwith_out"><code class="code"><span class="constructor">CCIO</span>.with_out</code></a>.<br>
|
|
<b>Since</b> 0.12<br>
|
|
<b>Raises</b> <code>Sys_error</code> in case of error<br>
|
|
</div>
|
|
<div class="param_info"><code class="code">flags</code> : opening flags (default <code class="code">[<span class="constructor">Open_creat</span>]</code>)</div>
|
|
<br>
|
|
<h2 id="2_MiscforGenerators">Misc for Generators</h2><br>
|
|
|
|
<pre><span id="VALtee"><span class="keyword">val</span> tee</span> : <code class="type">('a -> unit) list -> 'a <a href="CCIO.html#TYPEgen">gen</a> -> 'a <a href="CCIO.html#TYPEgen">gen</a></code></pre><div class="info ">
|
|
<code class="code">tee funs gen</code> behaves like <code class="code">gen</code>, but each element is given to
|
|
every function <code class="code">f</code> in <code class="code">funs</code> at the time the element is produced.<br>
|
|
</div>
|
|
<br>
|
|
<h2 id="2_Fileandfilenames">File and file names</h2>
|
|
<p>
|
|
|
|
How to list recursively files in a directory:
|
|
<pre class="codepre"><code class="code"> <span class="keywordsign">#</span> <span class="keyword">let</span> files = <span class="constructor">CCIO</span>.<span class="constructor">File</span>.read_dir ~recurse:<span class="keyword">true</span> (<span class="constructor">CCIO</span>.<span class="constructor">File</span>.make <span class="string">"/tmp"</span>);;
|
|
<span class="keywordsign">#</span> <span class="constructor">CCIO</span>.write_lines stdout files;;
|
|
</code></pre>
|
|
<p>
|
|
|
|
See <a href="CCIO.File.html#VALwalk"><code class="code"><span class="constructor">CCIO</span>.<span class="constructor">File</span>.walk</code></a> if you also need to list directories:
|
|
<p>
|
|
|
|
<pre class="codepre"><code class="code"> <span class="keywordsign">#</span> <span class="keyword">let</span> content = <span class="constructor">CCIO</span>.<span class="constructor">File</span>.walk (<span class="constructor">CCIO</span>.<span class="constructor">File</span>.make <span class="string">"/tmp"</span>);;
|
|
<span class="keywordsign">#</span> <span class="constructor">Gen</span>.map <span class="constructor">CCIO</span>.<span class="constructor">File</span>.show_walk_item content |> <span class="constructor">CCIO</span>.write_lines stdout;;
|
|
</code></pre><br>
|
|
|
|
<pre><span class="keyword">module</span> <a href="CCIO.File.html">File</a>: <code class="code"><span class="keyword">sig</span></code> <a href="CCIO.File.html">..</a> <code class="code"><span class="keyword">end</span></code></pre></body></html> |