System.IO.HVIO

MissingH-1.4.1.0: Large utility library

Copyright | Copyright (C) 2004-2011 John Goerzen
License | BSD3
Maintainer | John Goerzen <jgoerzen@complete.org>
Stability | provisional
Portability | portable
Safe Haskell | Safe
Language | Haskell98

System.IO.HVIO

Contents

- Implementation Classes
- Standard HVIO Implementations
  - Handle
  - Stream Reader
  - Memory Buffer
  - Haskell Pipe

Description

Haskell Virtual I/O -- a system to increase the flexibility of input and output in Haskell

Copyright (c) 2004-2005 John Goerzen, jgoerzen@complete.org

HVIO provides the following general features:

- 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.
- 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.
- The ability to define new objects that have the properties of I/O objects and can be used interchangably with them.
- Specification compatibility with, and complete support for, existing I/O on Handles.
- Provide easier unit testing capabilities for I/O actions

HVIO defines several basic type classes that you can use. You will mostly be interested in `HVIO`.

It's trivial to adapt old code to work with HVIO. For instance, consider this example of old and new code:

    printMsg :: Handle -> String -> IO ()
    printMsg h msg = hPutStr h ("msg: " ++ msg)

And now, the new way:

    printMsg :: HVIO h => h -> String -> IO ()
    printMsg h msg = vPutStr h ("msg: " ++ msg)

There are several points to note about this conversion:

- 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.
- 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.
- 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.

In addition to Handle, there are several pre-defined classes for your use. `StreamReader` 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 `StreamReader` with a call to `newStreamReader`.

`MemoryBuffer` is a similar class, but with a different purpose. It provides a full interface like Handle (it implements `HVIOReader`, `HVIOWriter`, and `HVIOSeeker`). 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 `MemoryBuffer` with a call to `newMemoryBuffer`.

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 `PipeReader` and a `PipeWriter`. You must use the `PipeWriter` in one thread and the `PipeReader` in another thread. Data that's written to the `PipeWriter` will then be available for reading with the `PipeReader`. 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 `newHVIOPipe`.

Together with System.IO.HVFS, this module is part of a complete virtual filesystem solution.

Synopsis

- class Show a => HVIO a where
  - vClose :: a -> IO ()
  - vIsOpen :: a -> IO Bool
  - vIsClosed :: a -> IO Bool
  - vTestOpen :: a -> IO ()
  - vIsEOF :: a -> IO Bool
  - vShow :: a -> IO String
  - vMkIOError :: a -> IOErrorType -> String -> Maybe FilePath -> IOError
  - vThrow :: a -> IOErrorType -> IO b
  - vGetFP :: a -> IO (Maybe FilePath)
  - vTestEOF :: a -> IO ()
  - vGetChar :: a -> IO Char
  - vGetLine :: a -> IO String
  - vGetContents :: a -> IO String
  - vReady :: a -> IO Bool
  - vIsReadable :: a -> IO Bool
  - vPutChar :: a -> Char -> IO ()
  - vPutStr :: a -> String -> IO ()
  - vPutStrLn :: a -> String -> IO ()
  - vPrint :: Show b => a -> b -> IO ()
  - vFlush :: a -> IO ()
  - vIsWritable :: a -> IO Bool
  - vSeek :: a -> SeekMode -> Integer -> IO ()
  - vTell :: a -> IO Integer
  - vRewind :: a -> IO ()
  - vIsSeekable :: a -> IO Bool
  - vSetBuffering :: a -> BufferMode -> IO ()
  - vGetBuffering :: a -> IO BufferMode
  - vPutBuf :: a -> Ptr b -> Int -> IO ()
  - vGetBuf :: a -> Ptr b -> Int -> IO Int
- data StreamReader
- newStreamReader :: String -> IO StreamReader
- data MemoryBuffer
- newMemoryBuffer :: String -> (String -> IO ()) -> IO MemoryBuffer
- mbDefaultCloseFunc :: String -> IO ()
- getMemoryBuffer :: MemoryBuffer -> IO String
- data PipeReader
- data PipeWriter
- newHVIOPipe :: IO (PipeReader, PipeWriter)

# Implementation Classes

class Show a => HVIO a where #

This is the generic I/O support class. All objects that are to be used in the HVIO system must provide an instance of `HVIO`.

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.

Instances of `HVIO` must provide `vClose`, `vIsEOF`, and either `vIsOpen` or `vIsClosed`.

Implementators of readable objects must provide at least `vGetChar` and `vIsReadable`. An implementation of `vGetContents` is also highly suggested, since the default cannot implement proper partial closing semantics.

Implementators of writable objects must provide at least `vPutChar` and `vIsWritable`.

Implementators of seekable objects must provide at least `vIsSeekable`, `vTell`, and `vSeek`.

Minimal complete definition

vClose, vIsEOF

Methods

vClose :: a -> IO () #

Close a file

vIsOpen :: a -> IO Bool #

Test if a file is open

vIsClosed :: a -> IO Bool #

Test if a file is closed

vTestOpen :: a -> IO () #

Raise an error if the file is not open. This is a new HVIO function and is implemented in terms of `vIsOpen`.

vIsEOF :: a -> IO Bool #

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.

vShow :: a -> IO String #

Detailed show output.

vMkIOError :: a -> IOErrorType -> String -> Maybe FilePath -> IOError #

Make an IOError.

vThrow :: a -> IOErrorType -> IO b #

Throw an IOError.

vGetFP :: a -> IO (Maybe FilePath) #

Get the filename/object/whatever that this corresponds to. May be Nothing.

vTestEOF :: a -> IO () #

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 `vIsEOF`.

vGetChar :: a -> IO Char #

Read one character

vGetLine :: a -> IO String #

Read one line

vGetContents :: a -> IO String #

Get the remaining contents. Please note that as a user of this function, the same partial-closing semantics as are used in the standard `hGetContents` are encouraged from implementators, but are not required. That means that, for instance, a `vGetChar` after a `vGetContents` 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 `vGetContents`. The bottom line: after a call to `vGetContents`, you should do nothing else with the object save closing it with `vClose`.

For implementators, you are highly encouraged to provide a correct implementation.

vReady :: a -> IO Bool #

Indicate whether at least one item is ready for reading. This will always be True for a great many implementations.

vIsReadable :: a -> IO Bool #

Indicate whether a particular item is available for reading.

vPutChar :: a -> Char -> IO () #

Write one character

vPutStr :: a -> String -> IO () #

Write a string

vPutStrLn :: a -> String -> IO () #

Write a string with newline character after it

vPrint :: Show b => a -> b -> IO () #

Write a string representation of the argument, plus a newline.

vFlush :: a -> IO () #

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.

vIsWritable :: a -> IO Bool #

Indicate whether or not this particular object supports writing.

vSeek :: a -> SeekMode -> Integer -> IO () #

Seek to a specific location.

vTell :: a -> IO Integer #

Get the current position.

vRewind :: a -> IO () #

Convenience function to reset the file pointer to the beginning of the file. A call to `vRewind h` is the same as ``vSeek` h AbsoluteSeek 0`.

vIsSeekable :: a -> IO Bool #

Indicate whether this instance supports seeking.

vSetBuffering :: a -> BufferMode -> IO () #

Set buffering; the default action is a no-op.

vGetBuffering :: a -> IO BufferMode #

Get buffering; the default action always returns NoBuffering.

vPutBuf :: a -> Ptr b -> Int -> IO () #

Binary output: write the specified number of octets from the specified buffer location.

vGetBuf :: a -> Ptr b -> Int -> IO Int #

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.

Instances

HVIO Handle # |
Instance details Defined in System.IO.HVIO Methods vClose :: Handle -> IO () # vIsOpen :: Handle -> IO Bool # vIsClosed :: Handle -> IO Bool # vTestOpen :: Handle -> IO () # vIsEOF :: Handle -> IO Bool # vShow :: Handle -> IO String # vMkIOError :: Handle -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: Handle -> IOErrorType -> IO b # vGetFP :: Handle -> IO (Maybe FilePath) # vTestEOF :: Handle -> IO () # vGetChar :: Handle -> IO Char # vGetLine :: Handle -> IO String # vGetContents :: Handle -> IO String # vReady :: Handle -> IO Bool # vIsReadable :: Handle -> IO Bool # vPutChar :: Handle -> Char -> IO () # vPutStr :: Handle -> String -> IO () # vPutStrLn :: Handle -> String -> IO () # vPrint :: Show b => Handle -> b -> IO () # vFlush :: Handle -> IO () # vIsWritable :: Handle -> IO Bool # vSeek :: Handle -> SeekMode -> Integer -> IO () # vTell :: Handle -> IO Integer # vRewind :: Handle -> IO () # vIsSeekable :: Handle -> IO Bool # vSetBuffering :: Handle -> BufferMode -> IO () # vGetBuffering :: Handle -> IO BufferMode # vPutBuf :: Handle -> Ptr b -> Int -> IO () # vGetBuf :: Handle -> Ptr b -> Int -> IO Int #
HVIO PipeWriter # |
Instance details Defined in System.IO.HVIO Methods vClose :: PipeWriter -> IO () # vIsOpen :: PipeWriter -> IO Bool # vIsClosed :: PipeWriter -> IO Bool # vTestOpen :: PipeWriter -> IO () # vIsEOF :: PipeWriter -> IO Bool # vShow :: PipeWriter -> IO String # vMkIOError :: PipeWriter -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: PipeWriter -> IOErrorType -> IO b # vGetFP :: PipeWriter -> IO (Maybe FilePath) # vTestEOF :: PipeWriter -> IO () # vGetChar :: PipeWriter -> IO Char # vGetLine :: PipeWriter -> IO String # vGetContents :: PipeWriter -> IO String # vReady :: PipeWriter -> IO Bool # vIsReadable :: PipeWriter -> IO Bool # vPutChar :: PipeWriter -> Char -> IO () # vPutStr :: PipeWriter -> String -> IO () # vPutStrLn :: PipeWriter -> String -> IO () # vPrint :: Show b => PipeWriter -> b -> IO () # vFlush :: PipeWriter -> IO () # vIsWritable :: PipeWriter -> IO Bool # vSeek :: PipeWriter -> SeekMode -> Integer -> IO () # vTell :: PipeWriter -> IO Integer # vRewind :: PipeWriter -> IO () # vIsSeekable :: PipeWriter -> IO Bool # vSetBuffering :: PipeWriter -> BufferMode -> IO () # vGetBuffering :: PipeWriter -> IO BufferMode # vPutBuf :: PipeWriter -> Ptr b -> Int -> IO () # vGetBuf :: PipeWriter -> Ptr b -> Int -> IO Int #
HVIO PipeReader # |
Instance details Defined in System.IO.HVIO Methods vClose :: PipeReader -> IO () # vIsOpen :: PipeReader -> IO Bool # vIsClosed :: PipeReader -> IO Bool # vTestOpen :: PipeReader -> IO () # vIsEOF :: PipeReader -> IO Bool # vShow :: PipeReader -> IO String # vMkIOError :: PipeReader -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: PipeReader -> IOErrorType -> IO b # vGetFP :: PipeReader -> IO (Maybe FilePath) # vTestEOF :: PipeReader -> IO () # vGetChar :: PipeReader -> IO Char # vGetLine :: PipeReader -> IO String # vGetContents :: PipeReader -> IO String # vReady :: PipeReader -> IO Bool # vIsReadable :: PipeReader -> IO Bool # vPutChar :: PipeReader -> Char -> IO () # vPutStr :: PipeReader -> String -> IO () # vPutStrLn :: PipeReader -> String -> IO () # vPrint :: Show b => PipeReader -> b -> IO () # vFlush :: PipeReader -> IO () # vIsWritable :: PipeReader -> IO Bool # vSeek :: PipeReader -> SeekMode -> Integer -> IO () # vTell :: PipeReader -> IO Integer # vRewind :: PipeReader -> IO () # vIsSeekable :: PipeReader -> IO Bool # vSetBuffering :: PipeReader -> BufferMode -> IO () # vGetBuffering :: PipeReader -> IO BufferMode # vPutBuf :: PipeReader -> Ptr b -> Int -> IO () # vGetBuf :: PipeReader -> Ptr b -> Int -> IO Int #
HVIO MemoryBuffer # |
Instance details Defined in System.IO.HVIO Methods vClose :: MemoryBuffer -> IO () # vIsOpen :: MemoryBuffer -> IO Bool # vIsClosed :: MemoryBuffer -> IO Bool # vTestOpen :: MemoryBuffer -> IO () # vIsEOF :: MemoryBuffer -> IO Bool # vShow :: MemoryBuffer -> IO String # vMkIOError :: MemoryBuffer -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: MemoryBuffer -> IOErrorType -> IO b # vGetFP :: MemoryBuffer -> IO (Maybe FilePath) # vTestEOF :: MemoryBuffer -> IO () # vGetChar :: MemoryBuffer -> IO Char # vGetLine :: MemoryBuffer -> IO String # vGetContents :: MemoryBuffer -> IO String # vReady :: MemoryBuffer -> IO Bool # vIsReadable :: MemoryBuffer -> IO Bool # vPutChar :: MemoryBuffer -> Char -> IO () # vPutStr :: MemoryBuffer -> String -> IO () # vPutStrLn :: MemoryBuffer -> String -> IO () # vPrint :: Show b => MemoryBuffer -> b -> IO () # vFlush :: MemoryBuffer -> IO () # vIsWritable :: MemoryBuffer -> IO Bool # vSeek :: MemoryBuffer -> SeekMode -> Integer -> IO () # vTell :: MemoryBuffer -> IO Integer # vRewind :: MemoryBuffer -> IO () # vIsSeekable :: MemoryBuffer -> IO Bool # vSetBuffering :: MemoryBuffer -> BufferMode -> IO () # vGetBuffering :: MemoryBuffer -> IO BufferMode # vPutBuf :: MemoryBuffer -> Ptr b -> Int -> IO () # vGetBuf :: MemoryBuffer -> Ptr b -> Int -> IO Int #
HVIO StreamReader # |
Instance details Defined in System.IO.HVIO Methods vClose :: StreamReader -> IO () # vIsOpen :: StreamReader -> IO Bool # vIsClosed :: StreamReader -> IO Bool # vTestOpen :: StreamReader -> IO () # vIsEOF :: StreamReader -> IO Bool # vShow :: StreamReader -> IO String # vMkIOError :: StreamReader -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: StreamReader -> IOErrorType -> IO b # vGetFP :: StreamReader -> IO (Maybe FilePath) # vTestEOF :: StreamReader -> IO () # vGetChar :: StreamReader -> IO Char # vGetLine :: StreamReader -> IO String # vGetContents :: StreamReader -> IO String # vReady :: StreamReader -> IO Bool # vIsReadable :: StreamReader -> IO Bool # vPutChar :: StreamReader -> Char -> IO () # vPutStr :: StreamReader -> String -> IO () # vPutStrLn :: StreamReader -> String -> IO () # vPrint :: Show b => StreamReader -> b -> IO () # vFlush :: StreamReader -> IO () # vIsWritable :: StreamReader -> IO Bool # vSeek :: StreamReader -> SeekMode -> Integer -> IO () # vTell :: StreamReader -> IO Integer # vRewind :: StreamReader -> IO () # vIsSeekable :: StreamReader -> IO Bool # vSetBuffering :: StreamReader -> BufferMode -> IO () # vGetBuffering :: StreamReader -> IO BufferMode # vPutBuf :: StreamReader -> Ptr b -> Int -> IO () # vGetBuf :: StreamReader -> Ptr b -> Int -> IO Int #

# Standard HVIO Implementations

## Handle

Handle is a member of `HVIO`.

## Stream Reader

data StreamReader #

Simulate I/O based on a string buffer.

When a `StreamReader` is created, it is initialized based on the contents of a `String`. Its contents are read lazily whenever a request is made to read something from the `StreamReader`. 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 `StreamReader` with a call to `newStreamReader`.

Instances

Show StreamReader # |
Instance details Defined in System.IO.HVIO Methods showsPrec :: Int -> StreamReader -> ShowS # show :: StreamReader -> String # showList :: [StreamReader] -> ShowS #
HVIO StreamReader # |
Instance details Defined in System.IO.HVIO Methods vClose :: StreamReader -> IO () # vIsOpen :: StreamReader -> IO Bool # vIsClosed :: StreamReader -> IO Bool # vTestOpen :: StreamReader -> IO () # vIsEOF :: StreamReader -> IO Bool # vShow :: StreamReader -> IO String # vMkIOError :: StreamReader -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: StreamReader -> IOErrorType -> IO b # vGetFP :: StreamReader -> IO (Maybe FilePath) # vTestEOF :: StreamReader -> IO () # vGetChar :: StreamReader -> IO Char # vGetLine :: StreamReader -> IO String # vGetContents :: StreamReader -> IO String # vReady :: StreamReader -> IO Bool # vIsReadable :: StreamReader -> IO Bool # vPutChar :: StreamReader -> Char -> IO () # vPutStr :: StreamReader -> String -> IO () # vPutStrLn :: StreamReader -> String -> IO () # vPrint :: Show b => StreamReader -> b -> IO () # vFlush :: StreamReader -> IO () # vIsWritable :: StreamReader -> IO Bool # vSeek :: StreamReader -> SeekMode -> Integer -> IO () # vTell :: StreamReader -> IO Integer # vRewind :: StreamReader -> IO () # vIsSeekable :: StreamReader -> IO Bool # vSetBuffering :: StreamReader -> BufferMode -> IO () # vGetBuffering :: StreamReader -> IO BufferMode # vPutBuf :: StreamReader -> Ptr b -> Int -> IO () # vGetBuf :: StreamReader -> Ptr b -> Int -> IO Int #

newStreamReader #

Arguments

:: String | Initial contents of the `StreamReader`
-> IO StreamReader |

Create a new `StreamReader` object.

## Memory Buffer

data MemoryBuffer #

A `MemoryBuffer` simulates true I/O, but uses an in-memory buffer instead of on-disk storage.

It provides a full interface like Handle (it implements `HVIOReader`, `HVIOWriter`, and `HVIOSeeker`). 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 `MemoryBuffer` with a call to `newMemoryBuffer`.

The present `MemoryBuffer` 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.

Instances

Show MemoryBuffer # |
Instance details Defined in System.IO.HVIO Methods showsPrec :: Int -> MemoryBuffer -> ShowS # show :: MemoryBuffer -> String # showList :: [MemoryBuffer] -> ShowS #
HVIO MemoryBuffer # |
Instance details Defined in System.IO.HVIO Methods vClose :: MemoryBuffer -> IO () # vIsOpen :: MemoryBuffer -> IO Bool # vIsClosed :: MemoryBuffer -> IO Bool # vTestOpen :: MemoryBuffer -> IO () # vIsEOF :: MemoryBuffer -> IO Bool # vShow :: MemoryBuffer -> IO String # vMkIOError :: MemoryBuffer -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: MemoryBuffer -> IOErrorType -> IO b # vGetFP :: MemoryBuffer -> IO (Maybe FilePath) # vTestEOF :: MemoryBuffer -> IO () # vGetChar :: MemoryBuffer -> IO Char # vGetLine :: MemoryBuffer -> IO String # vGetContents :: MemoryBuffer -> IO String # vReady :: MemoryBuffer -> IO Bool # vIsReadable :: MemoryBuffer -> IO Bool # vPutChar :: MemoryBuffer -> Char -> IO () # vPutStr :: MemoryBuffer -> String -> IO () # vPutStrLn :: MemoryBuffer -> String -> IO () # vPrint :: Show b => MemoryBuffer -> b -> IO () # vFlush :: MemoryBuffer -> IO () # vIsWritable :: MemoryBuffer -> IO Bool # vSeek :: MemoryBuffer -> SeekMode -> Integer -> IO () # vTell :: MemoryBuffer -> IO Integer # vRewind :: MemoryBuffer -> IO () # vIsSeekable :: MemoryBuffer -> IO Bool # vSetBuffering :: MemoryBuffer -> BufferMode -> IO () # vGetBuffering :: MemoryBuffer -> IO BufferMode # vPutBuf :: MemoryBuffer -> Ptr b -> Int -> IO () # vGetBuf :: MemoryBuffer -> Ptr b -> Int -> IO Int #

newMemoryBuffer #

Arguments

:: String | Initial Contents
-> (String -> IO ()) | close func
-> IO MemoryBuffer |

Create a new `MemoryBuffer` instance. The buffer is initialized to the value passed, and the pointer is placed at the beginning of the file.

You can put things in it by using the normal `vPutStr` calls, and reset to the beginning by using the normal `vRewind` call.

The function is called when `vClose` is called, and is passed the contents of the buffer at close time. You can use `mbDefaultCloseFunc` if you don't want to do anything.

To create an empty buffer, pass the initial value `""`.

mbDefaultCloseFunc :: String -> IO () #

Default (no-op) memory buf close function.

getMemoryBuffer :: MemoryBuffer -> IO String #

Grab the entire contents of the buffer as a string. Unlike `vGetContents`, this has no effect on the open status of the item, the EOF status, or the current position of the file pointer.

## Haskell Pipe

data PipeReader #

The reading side of a Haskell pipe. Please see `newHVIOPipe` for more details.

Instances

Show PipeReader # |
Instance details Defined in System.IO.HVIO Methods showsPrec :: Int -> PipeReader -> ShowS # show :: PipeReader -> String # showList :: [PipeReader] -> ShowS #
HVIO PipeReader # |
Instance details Defined in System.IO.HVIO Methods vClose :: PipeReader -> IO () # vIsOpen :: PipeReader -> IO Bool # vIsClosed :: PipeReader -> IO Bool # vTestOpen :: PipeReader -> IO () # vIsEOF :: PipeReader -> IO Bool # vShow :: PipeReader -> IO String # vMkIOError :: PipeReader -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: PipeReader -> IOErrorType -> IO b # vGetFP :: PipeReader -> IO (Maybe FilePath) # vTestEOF :: PipeReader -> IO () # vGetChar :: PipeReader -> IO Char # vGetLine :: PipeReader -> IO String # vGetContents :: PipeReader -> IO String # vReady :: PipeReader -> IO Bool # vIsReadable :: PipeReader -> IO Bool # vPutChar :: PipeReader -> Char -> IO () # vPutStr :: PipeReader -> String -> IO () # vPutStrLn :: PipeReader -> String -> IO () # vPrint :: Show b => PipeReader -> b -> IO () # vFlush :: PipeReader -> IO () # vIsWritable :: PipeReader -> IO Bool # vSeek :: PipeReader -> SeekMode -> Integer -> IO () # vTell :: PipeReader -> IO Integer # vRewind :: PipeReader -> IO () # vIsSeekable :: PipeReader -> IO Bool # vSetBuffering :: PipeReader -> BufferMode -> IO () # vGetBuffering :: PipeReader -> IO BufferMode # vPutBuf :: PipeReader -> Ptr b -> Int -> IO () # vGetBuf :: PipeReader -> Ptr b -> Int -> IO Int #

data PipeWriter #

The writing side of a Haskell pipe. Please see `newHVIOPipe` for more details.

Instances

Show PipeWriter # |
Instance details Defined in System.IO.HVIO Methods showsPrec :: Int -> PipeWriter -> ShowS # show :: PipeWriter -> String # showList :: [PipeWriter] -> ShowS #
HVIO PipeWriter # |
Instance details Defined in System.IO.HVIO Methods vClose :: PipeWriter -> IO () # vIsOpen :: PipeWriter -> IO Bool # vIsClosed :: PipeWriter -> IO Bool # vTestOpen :: PipeWriter -> IO () # vIsEOF :: PipeWriter -> IO Bool # vShow :: PipeWriter -> IO String # vMkIOError :: PipeWriter -> IOErrorType -> String -> Maybe FilePath -> IOError # vThrow :: PipeWriter -> IOErrorType -> IO b # vGetFP :: PipeWriter -> IO (Maybe FilePath) # vTestEOF :: PipeWriter -> IO () # vGetChar :: PipeWriter -> IO Char # vGetLine :: PipeWriter -> IO String # vGetContents :: PipeWriter -> IO String # vReady :: PipeWriter -> IO Bool # vIsReadable :: PipeWriter -> IO Bool # vPutChar :: PipeWriter -> Char -> IO () # vPutStr :: PipeWriter -> String -> IO () # vPutStrLn :: PipeWriter -> String -> IO () # vPrint :: Show b => PipeWriter -> b -> IO () # vFlush :: PipeWriter -> IO () # vIsWritable :: PipeWriter -> IO Bool # vSeek :: PipeWriter -> SeekMode -> Integer -> IO () # vTell :: PipeWriter -> IO Integer # vRewind :: PipeWriter -> IO () # vIsSeekable :: PipeWriter -> IO Bool # vSetBuffering :: PipeWriter -> BufferMode -> IO () # vGetBuffering :: PipeWriter -> IO BufferMode # vPutBuf :: PipeWriter -> Ptr b -> Int -> IO () # vGetBuf :: PipeWriter -> Ptr b -> Int -> IO Int #

newHVIOPipe :: IO (PipeReader, PipeWriter) #

Create a Haskell pipe.

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 `PipeReader` and a `PipeWriter`. You must use the `PipeWriter` in one thread and the `PipeReader` in another thread. Data that's written to the `PipeWriter` will then be available for reading with the `PipeReader`. 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.