io-streams-1.5.2.2: Simple, composable, and easy-to-use stream I/O

Safe Haskell | None
Language | Haskell2010

System.IO.Streams.File

Contents

- File conversions

Description

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.

Synopsis

- 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

withFileAsInput #

Arguments

:: FilePath | file to open
-> (InputStream ByteString -> IO a) | function to run
-> IO a |

``withFileAsInput` name act` opens the specified file in "read mode" and passes the resulting `InputStream` 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 #

Arguments

:: 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 #

Arguments

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

withFileAsOutput #

Arguments

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

withFileAsOutputExt #

Arguments

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