121 lines
46 KiB
HTML
121 lines
46 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>System.IO.HVIO</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
|
|
window.onload = function () {pageLoad();setSynopsis("mini_System-IO-HVIO.html");};
|
|
//]]>
|
|
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">MissingH-1.3.0.1: Large utility library</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>Copyright (C) 2004-2011 John Goerzen</td></tr><tr><th>License</th><td>BSD3</td></tr><tr><th>Maintainer</th><td>John Goerzen <jgoerzen@complete.org></td></tr><tr><th>Stability</th><td>provisional</td></tr><tr><th>Portability</th><td>portable</td></tr><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell98</td></tr></table><p class="caption">System.IO.HVIO</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Implementation Classes</a></li><li><a href="#g:2">Standard HVIO Implementations</a><ul><li><a href="#g:3">Handle</a></li><li><a href="#g:4">Stream Reader</a></li><li><a href="#g:5">Memory Buffer</a></li><li><a href="#g:6">Haskell Pipe</a></li></ul></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Haskell Virtual I/O -- a system to increase the flexibility of input and
|
|
output in Haskell</p><p>Copyright (c) 2004-2005 John Goerzen, jgoerzen@complete.org</p><p>HVIO provides the following general features:</p><ul><li>The ability to use a single set of functions on various different
|
|
types of objects, including standard Handles, in-memory buffers,
|
|
compressed files, network data streams, etc.</li><li>The ability to transparently add filters to the I/O process.
|
|
These filters could include things such as character set conversions,
|
|
compression or decompression of a data stream, and more.</li><li>The ability to define new objects that have the properties
|
|
of I/O objects and can be used interchangably with them.</li><li>Specification compatibility with, and complete support for,
|
|
existing I/O on Handles.</li><li>Provide easier unit testing capabilities for I/O actions</li></ul><p>HVIO defines several basic type classes that you can use. You will mostly
|
|
be interested in <code><a href="System-IO-HVIO.html#t:HVIO">HVIO</a></code>.</p><p>It's trivial to adapt old code to work with HVIO. For instance, consider
|
|
this example of old and new code:</p><pre>printMsg :: Handle -> String -> IO ()
|
|
printMsg h msg = hPutStr h ("msg: " ++ msg)</pre><p>And now, the new way:</p><pre>printMsg :: HVIO h => h -> String -> IO ()
|
|
printMsg h msg = vPutStr h ("msg: " ++ msg)</pre><p>There are several points to note about this conversion:</p><ul><li>The new method can still accept a Handle in exactly the same way as
|
|
the old method. Changing your functions to use HVIO will require no
|
|
changes from functions that call them with Handles.</li><li>Most "h" functions have equivolent "v" functions that operate
|
|
on HVIO classes instead of the more specific Handle. The "v" functions
|
|
behave identically to the "h" functions whenever possible.</li><li>There is no equivolent of "openFile" in any HVIO class. You must
|
|
create your Handle (or other HVIO object) using normal means.
|
|
This is because the creation is so different that it cannot be standardized.</li></ul><p>In addition to Handle, there are several pre-defined classes for your use.
|
|
<code><a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></code> is a particularly interesting one. At creation time, you pass
|
|
it a String. Its contents are read lazily whenever a read call is made. It
|
|
can be used, therefore, to implement filters (simply initialize it with the
|
|
result from, say, a map over hGetContents from another HVIO object), codecs,
|
|
and simple I/O testing. Because it is lazy, it need not hold the entire
|
|
string in memory. You can create a <code><a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></code> with a call to
|
|
<code><a href="System-IO-HVIO.html#v:newStreamReader">newStreamReader</a></code>.</p><p><code><a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></code> is a similar class, but with a different purpose. It provides
|
|
a full interface like Handle (it implements <code>HVIOReader</code>, <code>HVIOWriter</code>,
|
|
and <code>HVIOSeeker</code>). However, it maintains an in-memory buffer with the
|
|
contents of the file, rather than an actual on-disk file. You can access
|
|
the entire contents of this buffer at any time. This can be quite useful
|
|
for testing I/O code, or for cases where existing APIs use I/O, but you
|
|
prefer a String representation. You can create a <code><a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></code> with a call
|
|
to <code><a href="System-IO-HVIO.html#v:newMemoryBuffer">newMemoryBuffer</a></code>.</p><p>Finally, there are pipes. These pipes are analogous to the Unix
|
|
pipes that are available from System.Posix, but don't require Unix and work
|
|
only in Haskell. When you create a pipe, you actually get two HVIO objects:
|
|
a <code><a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></code> and a <code><a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></code>. You must use the <code><a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></code> in one
|
|
thread and the <code><a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></code> in another thread. Data that's written to the
|
|
<code><a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></code> will then be available for reading with the <code><a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></code>. The
|
|
pipes are implemented completely with existing Haskell threading primitives,
|
|
and require no special operating system support. Unlike Unix pipes, these
|
|
pipes cannot be used across a fork(). Also unlike Unix pipes, these pipes
|
|
are portable and interact well with Haskell threads. A new pipe can be created
|
|
with a call to <code><a href="System-IO-HVIO.html#v:newHVIOPipe">newHVIOPipe</a></code>.</p><p>Together with <a href="System-IO-HVFS.html">System.IO.HVFS</a>, this module is part of a complete
|
|
virtual filesystem solution.</p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">class</span> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> a => <a href="#t:HVIO">HVIO</a> a <span class="keyword">where</span><ul class="subs"><li><a href="#v:vClose">vClose</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vIsOpen">vIsOpen</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:vIsClosed">vIsClosed</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:vTestOpen">vTestOpen</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vIsEOF">vIsEOF</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:vShow">vShow</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></li><li><a href="#v:vMkIOError">vMkIOError</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO-Error.html#t:IOErrorType">IOErrorType</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="System-IO-HVFS.html#t:FilePath">FilePath</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO-Error.html#t:IOError">IOError</a></li><li><a href="#v:vThrow">vThrow</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO-Error.html#t:IOErrorType">IOErrorType</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> b</li><li><a href="#v:vGetFP">vGetFP</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="System-IO-HVFS.html#t:FilePath">FilePath</a>)</li><li><a href="#v:vTestEOF">vTestEOF</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vGetChar">vGetChar</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Char.html#t:Char">Char</a></li><li><a href="#v:vGetLine">vGetLine</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></li><li><a href="#v:vGetContents">vGetContents</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></li><li><a href="#v:vReady">vReady</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:vIsReadable">vIsReadable</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:vPutChar">vPutChar</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Char.html#t:Char">Char</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vPutStr">vPutStr</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vPutStrLn">vPutStrLn</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vPrint">vPrint</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> b => a -> b -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vFlush">vFlush</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vIsWritable">vIsWritable</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:vSeek">vSeek</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Device.html#t:SeekMode">SeekMode</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer">Integer</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vTell">vTell</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer">Integer</a></li><li><a href="#v:vRewind">vRewind</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vIsSeekable">vIsSeekable</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></li><li><a href="#v:vSetBuffering">vSetBuffering</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:BufferMode">BufferMode</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vGetBuffering">vGetBuffering</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:BufferMode">BufferMode</a></li><li><a href="#v:vPutBuf">vPutBuf</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Foreign-Ptr.html#t:Ptr">Ptr</a> b -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li><a href="#v:vGetBuf">vGetBuf</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Foreign-Ptr.html#t:Ptr">Ptr</a> b -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></li></ul></li><li class="src short"><span class="keyword">data</span> <a href="#t:StreamReader">StreamReader</a></li><li class="src short"><a href="#v:newStreamReader">newStreamReader</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:MemoryBuffer">MemoryBuffer</a></li><li class="src short"><a href="#v:newMemoryBuffer">newMemoryBuffer</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()) -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></li><li class="src short"><a href="#v:mbDefaultCloseFunc">mbDefaultCloseFunc</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</li><li class="src short"><a href="#v:getMemoryBuffer">getMemoryBuffer</a> :: <a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:PipeReader">PipeReader</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:PipeWriter">PipeWriter</a></li><li class="src short"><a href="#v:newHVIOPipe">newHVIOPipe</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a>, <a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a>)</li></ul></div><div id="interface"><h1 id="g:1">Implementation Classes</h1><div class="top"><p class="src"><span class="keyword">class</span> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> a => <a name="t:HVIO" class="def">HVIO</a> a <span class="keyword">where</span></p><div class="doc"><p>This is the generic I/O support class. All objects that are to be used
|
|
in the HVIO system must provide an instance of <code><a href="System-IO-HVIO.html#t:HVIO">HVIO</a></code>.</p><p>Functions in this class provide an interface with the same specification as
|
|
the similar functions in System.IO. Please refer to that documentation
|
|
for a more complete specification than is provided here.</p><p>Instances of <code><a href="System-IO-HVIO.html#t:HVIO">HVIO</a></code> must provide <code><a href="System-IO-HVIO.html#v:vClose">vClose</a></code>, <code><a href="System-IO-HVIO.html#v:vIsEOF">vIsEOF</a></code>, and either
|
|
<code><a href="System-IO-HVIO.html#v:vIsOpen">vIsOpen</a></code> or <code><a href="System-IO-HVIO.html#v:vIsClosed">vIsClosed</a></code>.</p><p>Implementators of readable objects must provide at least <code><a href="System-IO-HVIO.html#v:vGetChar">vGetChar</a></code>
|
|
and <code><a href="System-IO-HVIO.html#v:vIsReadable">vIsReadable</a></code>.
|
|
An implementation of <code><a href="System-IO-HVIO.html#v:vGetContents">vGetContents</a></code> is also highly suggested, since
|
|
the default cannot implement proper partial closing semantics.</p><p>Implementators of writable objects must provide at least <code><a href="System-IO-HVIO.html#v:vPutChar">vPutChar</a></code> and
|
|
<code><a href="System-IO-HVIO.html#v:vIsWritable">vIsWritable</a></code>.</p><p>Implementators of seekable objects must provide at least
|
|
<code><a href="System-IO-HVIO.html#v:vIsSeekable">vIsSeekable</a></code>, <code><a href="System-IO-HVIO.html#v:vTell">vTell</a></code>, and <code><a href="System-IO-HVIO.html#v:vSeek">vSeek</a></code>.</p></div><div class="subs minimal"><p class="caption">Minimal complete definition</p><p class="src"><a href="System-IO-HVIO.html#v:vClose">vClose</a>, <a href="System-IO-HVIO.html#v:vIsEOF">vIsEOF</a></p></div><div class="subs methods"><p class="caption">Methods</p><p class="src"><a name="v:vClose" class="def">vClose</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Close a file</p></div><p class="src"><a name="v:vIsOpen" class="def">vIsOpen</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Test if a file is open</p></div><p class="src"><a name="v:vIsClosed" class="def">vIsClosed</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Test if a file is closed</p></div><p class="src"><a name="v:vTestOpen" class="def">vTestOpen</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Raise an error if the file is not open.
|
|
This is a new HVIO function and is implemented in terms of
|
|
<code><a href="System-IO-HVIO.html#v:vIsOpen">vIsOpen</a></code>.</p></div><p class="src"><a name="v:vIsEOF" class="def">vIsEOF</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Whether or not we're at EOF. This may raise on exception
|
|
on some items, most notably write-only Handles such as stdout.
|
|
In general, this is most reliable on items opened for reading.
|
|
vIsEOF implementations must implicitly call vTestOpen.</p></div><p class="src"><a name="v:vShow" class="def">vShow</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></p><div class="doc"><p>Detailed show output.</p></div><p class="src"><a name="v:vMkIOError" class="def">vMkIOError</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO-Error.html#t:IOErrorType">IOErrorType</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="System-IO-HVFS.html#t:FilePath">FilePath</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO-Error.html#t:IOError">IOError</a></p><div class="doc"><p>Make an IOError.</p></div><p class="src"><a name="v:vThrow" class="def">vThrow</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO-Error.html#t:IOErrorType">IOErrorType</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> b</p><div class="doc"><p>Throw an IOError.</p></div><p class="src"><a name="v:vGetFP" class="def">vGetFP</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Maybe.html#t:Maybe">Maybe</a> <a href="System-IO-HVFS.html#t:FilePath">FilePath</a>)</p><div class="doc"><p>Get the filename/object/whatever that this corresponds to.
|
|
May be Nothing.</p></div><p class="src"><a name="v:vTestEOF" class="def">vTestEOF</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Throw an isEOFError if we're at EOF; returns nothing otherwise.
|
|
If an implementation overrides the default, make sure that it
|
|
calls vTestOpen at some point. The default implementation is
|
|
a wrapper around a call to <code><a href="System-IO-HVIO.html#v:vIsEOF">vIsEOF</a></code>.</p></div><p class="src"><a name="v:vGetChar" class="def">vGetChar</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Char.html#t:Char">Char</a></p><div class="doc"><p>Read one character</p></div><p class="src"><a name="v:vGetLine" class="def">vGetLine</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></p><div class="doc"><p>Read one line</p></div><p class="src"><a name="v:vGetContents" class="def">vGetContents</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></p><div class="doc"><p>Get the remaining contents. Please note that as a user of this
|
|
function, the same partial-closing semantics as are used in the
|
|
standard <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#v:hGetContents">hGetContents</a></code> are <em>encouraged</em> from implementators,
|
|
but are not <em>required</em>. That means that, for instance,
|
|
a <code><a href="System-IO-HVIO.html#v:vGetChar">vGetChar</a></code> after a <code><a href="System-IO-HVIO.html#v:vGetContents">vGetContents</a></code> may return some undefined
|
|
result instead of the error you would normally get. You should
|
|
use caution to make sure your code doesn't fall into that trap,
|
|
or make sure to test your code with Handle or one of the
|
|
default instances defined in this module. Also, some implementations
|
|
may essentially provide a complete close after a call to <code><a href="System-IO-HVIO.html#v:vGetContents">vGetContents</a></code>.
|
|
The bottom line: after a call to <code><a href="System-IO-HVIO.html#v:vGetContents">vGetContents</a></code>, you should do nothing
|
|
else with the object save closing it with <code><a href="System-IO-HVIO.html#v:vClose">vClose</a></code>.</p><p>For implementators, you are highly encouraged to provide a correct
|
|
implementation. </p></div><p class="src"><a name="v:vReady" class="def">vReady</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Indicate whether at least one item is ready for reading.
|
|
This will always be True for a great many implementations.</p></div><p class="src"><a name="v:vIsReadable" class="def">vIsReadable</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Indicate whether a particular item is available for reading.</p></div><p class="src"><a name="v:vPutChar" class="def">vPutChar</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Char.html#t:Char">Char</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Write one character</p></div><p class="src"><a name="v:vPutStr" class="def">vPutStr</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Write a string</p></div><p class="src"><a name="v:vPutStrLn" class="def">vPutStrLn</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Write a string with newline character after it</p></div><p class="src"><a name="v:vPrint" class="def">vPrint</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> b => a -> b -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Write a string representation of the argument, plus a newline.</p></div><p class="src"><a name="v:vFlush" class="def">vFlush</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Flush any output buffers.
|
|
Note: implementations should assure that a vFlush is automatically
|
|
performed
|
|
on file close, if necessary to ensure all data sent is written.</p></div><p class="src"><a name="v:vIsWritable" class="def">vIsWritable</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Indicate whether or not this particular object supports writing.</p></div><p class="src"><a name="v:vSeek" class="def">vSeek</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Device.html#t:SeekMode">SeekMode</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer">Integer</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Seek to a specific location.</p></div><p class="src"><a name="v:vTell" class="def">vTell</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Prelude.html#t:Integer">Integer</a></p><div class="doc"><p>Get the current position.</p></div><p class="src"><a name="v:vRewind" class="def">vRewind</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Convenience function to reset the file pointer to the beginning
|
|
of the file. A call to <code>vRewind h</code> is the
|
|
same as <code><code><a href="System-IO-HVIO.html#v:vSeek">vSeek</a></code> h AbsoluteSeek 0</code>.</p></div><p class="src"><a name="v:vIsSeekable" class="def">vIsSeekable</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Bool.html#t:Bool">Bool</a></p><div class="doc"><p>Indicate whether this instance supports seeking.</p></div><p class="src"><a name="v:vSetBuffering" class="def">vSetBuffering</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:BufferMode">BufferMode</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Set buffering; the default action is a no-op.</p></div><p class="src"><a name="v:vGetBuffering" class="def">vGetBuffering</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:BufferMode">BufferMode</a></p><div class="doc"><p>Get buffering; the default action always returns NoBuffering.</p></div><p class="src"><a name="v:vPutBuf" class="def">vPutBuf</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Foreign-Ptr.html#t:Ptr">Ptr</a> b -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Binary output: write the specified number of octets from the specified
|
|
buffer location.</p></div><p class="src"><a name="v:vGetBuf" class="def">vGetBuf</a> :: a -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Foreign-Ptr.html#t:Ptr">Ptr</a> b -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-Int.html#t:Int">Int</a></p><div class="doc"><p>Binary input: read the specified number of octets from the
|
|
specified buffer location, continuing to read
|
|
until it either consumes that much data or EOF is encountered.
|
|
Returns the number of octets actually read. EOF errors are never
|
|
raised; fewer bytes than requested are returned on EOF.</p></div></div><div class="subs instances"><p id="control.i:HVIO" class="caption collapser" onclick="toggleSection('i:HVIO')">Instances</p><div id="section.i:HVIO" class="show"><table><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/GHC-IO-Handle.html#t:Handle">Handle</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:2">Standard HVIO Implementations</h1><h2 id="g:3">Handle</h2><div class="doc"><p>Handle is a member of <code><a href="System-IO-HVIO.html#t:HVIO">HVIO</a></code>.</p></div><h2 id="g:4">Stream Reader</h2><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:StreamReader" class="def">StreamReader</a></p><div class="doc"><p>Simulate I/O based on a string buffer.</p><p>When a <code><a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></code> is created, it is initialized based on the contents of
|
|
a <code><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></code>. Its contents are read lazily whenever a request is made to read
|
|
something from the <code><a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></code>. It
|
|
can be used, therefore, to implement filters (simply initialize it with the
|
|
result from, say, a map over hGetContents from another HVIO object), codecs,
|
|
and simple I/O testing. Because it is lazy, it need not hold the entire
|
|
string in memory. You can create a <code><a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></code> with a call to
|
|
<code><a href="System-IO-HVIO.html#v:newStreamReader">newStreamReader</a></code>.</p></div><div class="subs instances"><p id="control.i:StreamReader" class="caption collapser" onclick="toggleSection('i:StreamReader')">Instances</p><div id="section.i:StreamReader" class="show"><table><tr><td class="src"><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> <a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:newStreamReader" class="def">newStreamReader</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></td><td class="doc"><p>Initial contents of the <code><a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></code></p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Create a new <code><a href="System-IO-HVIO.html#t:StreamReader">StreamReader</a></code> object. </p></div></div><h2 id="g:5">Memory Buffer</h2><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:MemoryBuffer" class="def">MemoryBuffer</a></p><div class="doc"><p>A <code><a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></code> simulates true I/O, but uses an in-memory buffer instead
|
|
of on-disk storage.</p><p>It provides
|
|
a full interface like Handle (it implements <code>HVIOReader</code>, <code>HVIOWriter</code>,
|
|
and <code>HVIOSeeker</code>). However, it maintains an in-memory buffer with the
|
|
contents of the file, rather than an actual on-disk file. You can access
|
|
the entire contents of this buffer at any time. This can be quite useful
|
|
for testing I/O code, or for cases where existing APIs use I/O, but you
|
|
prefer a String representation. You can create a <code><a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></code> with a call
|
|
to <code><a href="System-IO-HVIO.html#v:newMemoryBuffer">newMemoryBuffer</a></code>.</p><p>The present <code><a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></code> implementation is rather inefficient, particularly
|
|
when reading towards the end of large files. It's best used for smallish
|
|
data storage. This problem will be fixed eventually.</p></div><div class="subs instances"><p id="control.i:MemoryBuffer" class="caption collapser" onclick="toggleSection('i:MemoryBuffer')">Instances</p><div id="section.i:MemoryBuffer" class="show"><table><tr><td class="src"><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> <a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:newMemoryBuffer" class="def">newMemoryBuffer</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></td><td class="doc"><p>Initial Contents</p></td></tr><tr><td class="src">-> (<a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ())</td><td class="doc"><p>close func</p></td></tr><tr><td class="src">-> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></td><td class="doc empty"> </td></tr></table></div><div class="doc"><p>Create a new <code><a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a></code> instance. The buffer is initialized
|
|
to the value passed, and the pointer is placed at the beginning of the file.</p><p>You can put things in it by using the normal <code><a href="System-IO-HVIO.html#v:vPutStr">vPutStr</a></code> calls, and reset to
|
|
the beginning by using the normal <code><a href="System-IO-HVIO.html#v:vRewind">vRewind</a></code> call.</p><p>The function is called when <code><a href="System-IO-HVIO.html#v:vClose">vClose</a></code> is called, and is passed the contents of
|
|
the buffer at close time. You can use <code><a href="System-IO-HVIO.html#v:mbDefaultCloseFunc">mbDefaultCloseFunc</a></code> if you don't want to
|
|
do anything.</p><p>To create an empty buffer, pass the initial value <code>""</code>. </p></div></div><div class="top"><p class="src"><a name="v:mbDefaultCloseFunc" class="def">mbDefaultCloseFunc</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> ()</p><div class="doc"><p>Default (no-op) memory buf close function. </p></div></div><div class="top"><p class="src"><a name="v:getMemoryBuffer" class="def">getMemoryBuffer</a> :: <a href="System-IO-HVIO.html#t:MemoryBuffer">MemoryBuffer</a> -> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Data-String.html#t:String">String</a></p><div class="doc"><p>Grab the entire contents of the buffer as a string.
|
|
Unlike <code><a href="System-IO-HVIO.html#v:vGetContents">vGetContents</a></code>, this has no effect on the open status of the
|
|
item, the EOF status, or the current position of the file pointer. </p></div></div><h2 id="g:6">Haskell Pipe</h2><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:PipeReader" class="def">PipeReader</a></p><div class="doc"><p>The reading side of a Haskell pipe. Please see <code><a href="System-IO-HVIO.html#v:newHVIOPipe">newHVIOPipe</a></code> for more
|
|
details. </p></div><div class="subs instances"><p id="control.i:PipeReader" class="caption collapser" onclick="toggleSection('i:PipeReader')">Instances</p><div id="section.i:PipeReader" class="show"><table><tr><td class="src"><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> <a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:PipeWriter" class="def">PipeWriter</a></p><div class="doc"><p>The writing side of a Haskell pipe. Please see <code><a href="System-IO-HVIO.html#v:newHVIOPipe">newHVIOPipe</a></code> for more
|
|
details. </p></div><div class="subs instances"><p id="control.i:PipeWriter" class="caption collapser" onclick="toggleSection('i:PipeWriter')">Instances</p><div id="section.i:PipeWriter" class="show"><table><tr><td class="src"><a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/Text-Show.html#t:Show">Show</a> <a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></td><td class="doc empty"> </td></tr><tr><td class="src"><a href="System-IO-HVIO.html#t:HVIO">HVIO</a> <a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><a name="v:newHVIOPipe" class="def">newHVIOPipe</a> :: <a href="file:///usr/local/Cellar/ghc/7.10.1/share/doc/ghc/html/libraries/base-4.8.0.0/System-IO.html#t:IO">IO</a> (<a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a>, <a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a>)</p><div class="doc"><p>Create a Haskell pipe.</p><p>These pipes are analogous to the Unix
|
|
pipes that are available from System.Posix, but don't require Unix and work
|
|
only in Haskell. When you create a pipe, you actually get two HVIO objects:
|
|
a <code><a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></code> and a <code><a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></code>. You must use the <code><a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></code> in one
|
|
thread and the <code><a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></code> in another thread. Data that's written to the
|
|
<code><a href="System-IO-HVIO.html#t:PipeWriter">PipeWriter</a></code> will then be available for reading with the <code><a href="System-IO-HVIO.html#t:PipeReader">PipeReader</a></code>. The
|
|
pipes are implemented completely with existing Haskell threading primitives,
|
|
and require no special operating system support. Unlike Unix pipes, these
|
|
pipes cannot be used across a fork(). Also unlike Unix pipes, these pipes
|
|
are portable and interact well with Haskell threads. </p></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.16.0</p></div></body></html> |