hGet

Read a ByteString directly from the specified Handle. This is far more efficient than reading the characters into a String and then using pack. First argument is the Handle to read from, and the second is the number of bytes to read. It returns the bytes read, up to n, or empty if EOF has been reached. hGet is implemented in terms of hGetBuf. If the handle is a pipe or socket, and the writing end is closed, hGet will behave as if EOF was reached.
Read n bytes into a ByteString, directly from the specified Handle.
Lifted hGet
Lifted hGet
Convert a handle into a byte stream using a fixed chunk size hGet waits until exactly the requested number of bytes are available for each chunk.
Read Bytes directly from the specified Handle. The resulting Bytes are pinned. This is implemented with hGetBuf.
Read n bytes into a ByteStream, directly from the specified Handle.
Read specified number of bytes. See hGet for particular semantics.
Read a Vector directly from the specified Handle. This is far more efficient than reading the characters into a list and then using pack.
Read binary data directly from the specified Handle. First argument is the Handle to read from, and the second is the number of bytes to read. It returns the bytes read, up to the specified size, or an empty array if EOF has been reached. hGet is implemented in terms of hGetBuf.
Gets any data from HSet for you
Heterogeneous read arbitrarily element from hset
>>> let x = HSCons (10 :: Int) $ HSCons (20 :: Double) HSNil

>>> x
HSCons (10) (HSCons (20.0) (HSNil))
>>> hget x :: Int
10
>>> hget x :: Double
20.0
Note that hget takes specific element from list of uniquely typed elements depending on what type is required to be returned (return type polymorphism)
hGetBuf hdl buf count reads data from the handle hdl into the buffer buf until either EOF is reached or count 8-bit bytes have been read. It returns the number of bytes actually read. This may be zero if EOF was reached before any data was read (or if count is zero). hGetBuf never raises an EOF exception, instead it returns a value smaller than count. If the handle is a pipe or socket, and the writing end is closed, hGetBuf will behave as if EOF was reached. hGetBuf ignores the prevailing TextEncoding and NewlineMode on the Handle, and reads bytes directly.
hGetBufNonBlocking hdl buf count reads data from the handle hdl into the buffer buf until either EOF is reached, or count 8-bit bytes have been read, or there is no more data available to read immediately. hGetBufNonBlocking is identical to hGetBuf, except that it will never block waiting for data to become available, instead it returns only whatever data is available. To wait for data to arrive before calling hGetBufNonBlocking, use hWaitForInput. If the handle is a pipe or socket, and the writing end is closed, hGetBufNonBlocking will behave as if EOF was reached. hGetBufNonBlocking ignores the prevailing TextEncoding and NewlineMode on the Handle, and reads bytes directly. NOTE: on Windows, this function does not work correctly; it behaves identically to hGetBuf.
hGetBufSome hdl buf count reads data from the handle hdl into the buffer buf. If there is any data available to read, then hGetBufSome returns it immediately; it only blocks if there is no data to be read. It returns the number of bytes actually read. This may be zero if EOF was reached before any data was read (or if count is zero). hGetBufSome never raises an EOF exception, instead it returns a value smaller than count. If the handle is a pipe or socket, and the writing end is closed, hGetBufSome will behave as if EOF was reached. hGetBufSome ignores the prevailing TextEncoding and NewlineMode on the Handle, and reads bytes directly.
Computation hGetBuffering hdl returns the current buffering mode for hdl.
Computation hGetChar hdl reads a character from the file or channel managed by hdl, blocking until a character is available. This operation may fail with:
Computation hGetContents hdl returns the list of characters corresponding to the unread portion of the channel or file managed by hdl, which is put into an intermediate state, semi-closed. In this state, hdl is effectively closed, but items are read from hdl on demand and accumulated in a special list returned by hGetContents hdl. Any operation that fails because a handle is closed, also fails if a handle is semi-closed. The only exception is hClose. A semi-closed handle becomes closed:
  • if hClose is applied to it;
  • if an I/O error occurs when reading an item from the handle;
  • or once the entire contents of the handle has been read.
Once a semi-closed handle becomes closed, the contents of the associated list becomes fixed. The contents of this final list is only partially specified: it will contain at least all the items of the stream that were evaluated prior to the handle becoming closed. Any I/O errors encountered while a handle is semi-closed are simply discarded. This operation may fail with:
The hGetContents' operation reads all input on the given handle before returning it as a String and closing the handle. This is a strict version of hGetContents
Get the echoing status of a handle connected to a terminal.
Return the current TextEncoding for the specified Handle, or Nothing if the Handle is in binary mode. Note that the TextEncoding remembers nothing about the state of the encoder/decoder in use on this Handle. For example, if the encoding in use is UTF-16, then using hGetEncoding and hSetEncoding to save and restore the encoding may result in an extra byte-order-mark being written to the file.
Computation hGetLine hdl reads a line from the file or channel managed by hdl. hGetLine does not return the newline as part of the result. A line is separated by the newline set with hSetNewlineMode or nativeNewline by default. The read newline character(s) are not returned as part of the result. If hGetLine encounters end-of-file at any point while reading in the middle of a line, it is treated as a line terminator and the (partial) line is returned. This operation may fail with:
  • isEOFError if the end of file is encountered when reading the first character of the line.

Examples

>>> withFile "/home/user/foo" ReadMode hGetLine >>= putStrLn
this is the first line of the file :O
>>> withFile "/home/user/bar" ReadMode (replicateM 3 . hGetLine)
["this is the first line","this is the second line","this is the third line"]