|
GHC.Handle | Portability | non-portable | Stability | internal | Maintainer | libraries@haskell.org |
|
|
|
Description |
This module defines the basic operations on I/O "handles".
|
|
Synopsis |
|
|
|
Documentation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
A handle managing input from the Haskell program's standard input channel.
|
|
|
A handle managing output to the Haskell program's standard output channel.
|
|
|
A handle managing output to the Haskell program's standard error channel.
|
|
|
Constructors | ReadMode | | WriteMode | | AppendMode | | ReadWriteMode | |
| Instances | |
|
|
|
Computation openFile file mode allocates and returns a new, open
handle to manage the file file. It manages input if mode
is ReadMode, output if mode is WriteMode or AppendMode,
and both input and output if mode is ReadWriteMode.
If the file does not exist and it is opened for output, it should be
created as a new file. If mode is WriteMode and the file
already exists, then it should be truncated to zero length.
Some operating systems delete empty files, so there is no guarantee
that the file will exist following an openFile with mode
WriteMode unless it is subsequently written to successfully.
The handle is positioned at the end of the file if mode is
AppendMode, and otherwise at the beginning (in which case its
internal position is 0).
The initial buffer mode is implementation-dependent.
This operation may fail with:
Note: if you will be working with files containing binary data, you'll want to
be using openBinaryFile.
|
|
|
Like openFile, but open the file in binary mode.
On Windows, reading a file in text mode (which is the default)
will translate CRLF to LF, and writing will translate LF to CRLF.
This is usually what you want with text files. With binary files
this is undesirable; also, as usual under Microsoft operating systems,
text mode treats control-Z as EOF. Binary mode turns off all special
treatment of end-of-line and end-of-file characters.
(See also hSetBinaryMode.)
|
|
|
|
|
|
|
Old API kept to avoid breaking clients
|
|
|
For a handle hdl which attached to a physical file,
hFileSize hdl returns the size of that file in 8-bit bytes.
|
|
|
hSetFileSize hdl size truncates the physical file with handle hdl to size bytes.
|
|
|
For a readable handle hdl, hIsEOF hdl returns
True if no further input can be taken from hdl or for a
physical file, if the current I/O position is equal to the length of
the file. Otherwise, it returns False.
|
|
|
The computation isEOF is identical to hIsEOF,
except that it works only on stdin.
|
|
|
Computation hLookAhead returns the next character from the handle
without removing it from the input buffer, blocking until a character
is available.
This operation may fail with:
|
|
|
Computation hSetBuffering hdl mode sets the mode of buffering for
handle hdl on subsequent reads and writes.
If the buffer mode is changed from BlockBuffering or
LineBuffering to NoBuffering, then
- if hdl is writable, the buffer is flushed as for hFlush;
- if hdl is not writable, the contents of the buffer is discarded.
This operation may fail with:
- isPermissionError if the handle has already been used for reading
or writing and the implementation does not allow the buffering mode
to be changed.
|
|
|
Select binary mode (True) or text mode (False) on a open handle.
(See also openBinaryFile.)
|
|
|
The action hFlush hdl causes any items buffered for output
in handle hdl to be sent immediately to the operating system.
This operation may fail with:
- isFullError if the device is full;
- isPermissionError if a system resource limit would be exceeded.
It is unspecified whether the characters in the buffer are discarded
or retained under these circumstances.
|
|
|
Returns a duplicate of the original handle, with its own buffer.
The two Handles will share a file pointer, however. The original
handle's buffer is flushed, including discarding any input data,
before the handle is duplicated.
|
|
|
Makes the second handle a duplicate of the first handle. The second
handle will be closed first, if it is not already.
This can be used to retarget the standard Handles, for example:
do h <- openFile "mystdout" WriteMode
hDuplicateTo h stdout
|
|
|
Computation hClose hdl makes handle hdl closed. Before the
computation finishes, if hdl is writable its buffer is flushed as
for hFlush.
Performing hClose on a handle that has already been closed has no effect;
doing so is not an error. All other operations on a closed handle will fail.
If hClose fails for any reason, any further operations (apart from
hClose) on the handle will still fail as if hdl had been successfully
closed.
|
|
|
|
|
|
|
Constructors | | Instances | |
|
|
|
Computation hGetPosn hdl returns the current I/O position of
hdl as a value of the abstract type HandlePosn.
|
|
|
If a call to hGetPosn hdl returns a position p,
then computation hSetPosn p sets the position of hdl
to the position it held at the time of the call to hGetPosn.
This operation may fail with:
|
|
|
A mode that determines the effect of hSeek hdl mode i, as follows:
| Constructors | AbsoluteSeek | the position of hdl is set to i.
| RelativeSeek | the position of hdl is set to offset i
from the current position.
| SeekFromEnd | the position of hdl is set to offset i
from the end of the file.
|
| Instances | |
|
|
|
Computation hSeek hdl mode i sets the position of handle
hdl depending on mode.
The offset i is given in terms of 8-bit bytes.
If hdl is block- or line-buffered, then seeking to a position which is not
in the current buffer will first cause any items in the output buffer to be
written to the device, and then cause the input buffer to be discarded.
Some handles may not be seekable (see hIsSeekable), or only support a
subset of the possible positioning operations (for instance, it may only
be possible to seek to the end of a tape, or to a positive offset from
the beginning or current position).
It is not possible to set a negative I/O position, or for
a physical file, an I/O position beyond the current end-of-file.
This operation may fail with:
|
|
|
|
|
|
|
|
|
|
|
|
|
Computation hGetBuffering hdl returns the current buffering mode
for hdl.
|
|
|
|
|
Set the echoing status of a handle connected to a terminal.
|
|
|
Get the echoing status of a handle connected to a terminal.
|
|
|
Is the handle connected to a terminal?
|
|
|
hShow is in the IO monad, and gives more comprehensive output
than the (pure) instance of Show for Handle.
|
|
Produced by Haddock version 2.0.0.0 |