Safe Haskell | None |
---|---|
Language | Haskell2010 |
Input and output streams for files.
The functions in this file use "with*" or "bracket" semantics, i.e. they
open the supplied FilePath
, run a user computation, and then close the
file handle. If you need more control over the lifecycle of the underlying
file descriptor resources, you are encouraged to use the functions from
System.IO.Streams.Handle instead.
- withFileAsInput :: FilePath -> (InputStream ByteString -> IO a) -> IO a
- withFileAsInputStartingAt :: Int64 -> FilePath -> (InputStream ByteString -> IO a) -> IO a
- unsafeWithFileAsInputStartingAt :: Int64 -> FilePath -> (InputStream ByteString -> IO a) -> IO a
- withFileAsOutput :: FilePath -> (OutputStream ByteString -> IO a) -> IO a
- withFileAsOutputExt :: FilePath -> IOMode -> BufferMode -> (OutputStream ByteString -> IO a) -> IO a
File conversions
:: FilePath | file to open |
-> (InputStream ByteString -> IO a) | function to run |
-> IO a |
opens the specified file in "read mode" and
passes the resulting withFileAsInput
name actInputStream
to the computation act
. The file will
be closed on exit from withFileAsInput
, whether by normal termination or
by raising an exception.
If closing the file raises an exception, then that exception will be
raised by withFileAsInput
rather than any exception raised by act
.
withFileAsInputStartingAt Source #
:: Int64 | starting index to seek to |
-> FilePath | file to open |
-> (InputStream ByteString -> IO a) | function to run |
-> IO a |
Like withFileAsInput
, but seeks to the specified byte offset before
attaching the given file descriptor to the InputStream
.
unsafeWithFileAsInputStartingAt Source #
:: Int64 | starting index to seek to |
-> FilePath | file to open |
-> (InputStream ByteString -> IO a) | function to run |
-> IO a |
Like withFileAsInputStartingAt
, except that the ByteString
emitted by
the created InputStream
may reuse its buffer. You may only use this
function if you do not retain references to the generated bytestrings
emitted.
:: FilePath | file to open |
-> (OutputStream ByteString -> IO a) | function to run |
-> IO a |
Open a file for writing and attaches an OutputStream
for you to write
to. The file will be closed on error or completion of your action.
:: FilePath | file to open |
-> IOMode | mode to write in |
-> BufferMode | should we buffer the output? |
-> (OutputStream ByteString -> IO a) | function to run |
-> IO a |
Like withFileAsOutput
, but allowing you control over the output file
mode and buffering behaviour.