Relude.File

relude-1.2.2.0: Safe, performant, user-friendly and lightweight Haskell Standard Library

Copyright | (c) 2018-2023 Kowainik
License | MIT
Maintainer | Kowainik <xrom.xkov@gmail.com>
Stability | Stable
Portability | Portable
Safe Haskell | Safe
Language | Haskell2010

Relude.File

Contents

- Text
- Lazy Text
- ByteString
- Lazy ByteString

Description

Lifted to `MonadIO` families of file processing functions for the `Text`, `LText`, `ByteString` and `LByteString` types.

These functions are lifted which means that you can also use them inside various Monad Transformers without adding `liftIO` call explicitly.

NOTE: These functions are for working with textual data. Functions that work with `Text` or `LText` types are system and locale-sensitive (encoding, line-endings). If you want binary data, use `ByteString` functions (they are also faster since they don't check encoding). However, you can then decode that data with the help of functions from the Relude.String.Conversion module, e. g. `decodeUtf8`.

To be more precise, avoid the following functions:

- `readFileText`
- `readFileLText`

See the following blog post for more details:

- Beware of readFile by Michael Snoyman

Since: 0.3.0

Synopsis

- readFileText :: MonadIO m => FilePath -> m Text
- writeFileText :: MonadIO m => FilePath -> Text -> m ()
- appendFileText :: MonadIO m => FilePath -> Text -> m ()
- readFileLText :: MonadIO m => FilePath -> m LText
- writeFileLText :: MonadIO m => FilePath -> LText -> m ()
- appendFileLText :: MonadIO m => FilePath -> LText -> m ()
- readFileBS :: MonadIO m => FilePath -> m ByteString
- writeFileBS :: MonadIO m => FilePath -> ByteString -> m ()
- appendFileBS :: MonadIO m => FilePath -> ByteString -> m ()
- readFileLBS :: MonadIO m => FilePath -> m LByteString
- writeFileLBS :: MonadIO m => FilePath -> LByteString -> m ()
- appendFileLBS :: MonadIO m => FilePath -> LByteString -> m ()

# Text

readFileText :: MonadIO m => FilePath -> m Text #

Warning: `readFileText` depends on the system's locale settings and can throw unexpected exceptions.Use `readFileBS` instead.

Lifted version of `readFile`.

Since: 0.3.0

writeFileText :: MonadIO m => FilePath -> Text -> m () #

Lifted version of `writeFile`.

Since: 0.3.0

appendFileText :: MonadIO m => FilePath -> Text -> m () #

Lifted version of `appendFile`.

Since: 0.3.0

# Lazy Text

readFileLText :: MonadIO m => FilePath -> m LText #

Warning: `readFileLText` depends on the system's locale settings and can throw unexpected exceptions.Use `readFileLBS` instead.

Lifted version of `readFile`.

Since: 0.3.0

writeFileLText :: MonadIO m => FilePath -> LText -> m () #

Lifted version of `writeFile`.

Since: 0.3.0

appendFileLText :: MonadIO m => FilePath -> LText -> m () #

Lifted version of `appendFile`.

Since: 0.3.0

# ByteString

readFileBS :: MonadIO m => FilePath -> m ByteString #

Lifted version of `readFile`.

Since: 0.3.0

writeFileBS :: MonadIO m => FilePath -> ByteString -> m () #

Lifted version of `writeFile`.

Since: 0.3.0

appendFileBS :: MonadIO m => FilePath -> ByteString -> m () #

Lifted version of `appendFile`.

Since: 0.3.0

# Lazy ByteString

readFileLBS :: MonadIO m => FilePath -> m LByteString #

Lifted version of `readFile`.

Since: 0.3.0

writeFileLBS :: MonadIO m => FilePath -> LByteString -> m () #

Lifted version of `writeFile`.

Since: 0.3.0

appendFileLBS :: MonadIO m => FilePath -> LByteString -> m () #

Lifted version of `appendFile`.

Since: 0.3.0