System.FilePath.Manip

filemanip-0.3.6.3: Expressive file and directory manipulation for Haskell.

Copyright | Bryan O'Sullivan
License | BSD3
Maintainer | Bryan O'Sullivan <bos@serpentine.com>
Stability | unstable
Portability | Unix-like systems (requires flexible instances)
Safe Haskell | None
Language | Haskell98

System.FilePath.Manip

Description

Synopsis

- class Streamable a where
  - readAll :: Handle -> IO a
  - writeAll :: Handle -> a -> IO ()
- renameWith :: (FilePath -> FilePath) -> FilePath -> IO ()
- modifyWith :: Streamable a => (FilePath -> FilePath -> IO ()) -> (a -> a) -> FilePath -> IO ()
- modifyWithBackup :: Streamable a => (FilePath -> FilePath) -> (a -> a) -> FilePath -> IO ()
- modifyInPlace :: Streamable a => (a -> a) -> FilePath -> IO ()

# Documentation

class Streamable a where #

Type class for string manipulation over files.

Methods

readAll :: Handle -> IO a #

Read the entire contents of a `Handle`.

writeAll :: Handle -> a -> IO () #

Write an entire string to a `Handle`.

#### Instances

Instances details

Streamable ByteString # |
Instance details Defined in System.FilePath.Manip Methods readAll :: Handle -> IO ByteString # writeAll :: Handle -> ByteString -> IO () #
Streamable ByteString # |
Instance details Defined in System.FilePath.Manip Methods readAll :: Handle -> IO ByteString # writeAll :: Handle -> ByteString -> IO () #
Streamable String # |
Instance details Defined in System.FilePath.Manip Methods readAll :: Handle -> IO String # writeAll :: Handle -> String -> IO () #

renameWith #

Arguments

:: (FilePath -> FilePath) | function to rename with
-> FilePath | file to rename
-> IO () |

Use a renaming function to generate a new name for a file, then rename it.

modifyWith #

Arguments

:: Streamable a |
=> (FilePath -> FilePath -> IO ()) | file manipulation action
-> (a -> a) | transformation function
-> FilePath |
-> IO () |

Modify a file in place using the given function. The new content is written to a temporary file. Once this is complete, the file manipulation action is called. Its arguments are the names of the original and temporary files.

Example:

        modifyInPlace = modifyWith (flip rename)

modifyWithBackup #

Arguments

:: Streamable a |
=> (FilePath -> FilePath) | chooses new name for original file
-> (a -> a) | transformation function
-> FilePath | name of file to modify
-> IO () |

Modify a file in place using the given function. The original copy of the file is saved under a new name. This is performed by writing to a temporary file; renaming the original file to its new name; then renaming the temporary file to the original name.

Example:

        -- save original file with a ".bak" extension
        modifyWithBackup (<.> "bak")

modifyInPlace #

Arguments

:: Streamable a |
=> (a -> a) | transformation function
-> FilePath | name of file to modify
-> IO () |

Modify a file in place using the given function. This is performed by writing to a temporary file, then renaming it on top of the existing file when done.