LambdaHack-0.11.0.1: A game engine library for tactical squad ASCII roguelike dungeon crawlers

Safe Haskell | None
Language | Haskell2010

Game.LambdaHack.Common.File

Description

Saving/loading to files, with serialization and compression.

Synopsis

- encodeEOF :: Binary b => FilePath -> Version -> b -> IO ()
- strictDecodeEOF :: Binary b => FilePath -> IO (Version, b)
- tryCreateDir :: FilePath -> IO ()
- doesFileExist :: FilePath -> IO Bool
- tryWriteFile :: FilePath -> Text -> IO ()
- readFile :: FilePath -> IO String
- renameFile :: FilePath -> FilePath -> IO ()

# Documentation

encodeEOF :: Binary b => FilePath -> Version -> b -> IO () Source #

Serialize, compress and save data with an EOF marker. The `OK` is used as an EOF marker to ensure any apparent problems with corrupted files are reported to the user ASAP.

strictDecodeEOF :: Binary b => FilePath -> IO (Version, b) Source #

Read, decompress and deserialize data with an EOF marker. The `OK` EOF marker ensures any easily detectable file corruption is discovered and reported before any value is decoded from the second component and before the file handle is closed. OTOH, binary encoding corruption is not discovered until a version check elswere ensures that binary formats are compatible.

tryCreateDir :: FilePath -> IO () Source #

Try to create a directory, if it doesn't exist. We catch exceptions in case many clients try to do the same thing at the same time.

doesFileExist :: FilePath -> IO Bool Source #

The operation `doesFileExist` returns `True` if the argument file exists and is not a directory, and `False` otherwise.

tryWriteFile :: FilePath -> Text -> IO () Source #

Try to write a file, given content, if the file not already there. We catch exceptions in case many clients and/or the server try to do the same thing at the same time. Using `IO` to avoid UTF conflicts with OS or filesystem.

readFile :: FilePath -> IO String Source #

The `readFile` function reads a file and returns the contents of the file as a string. The file is read lazily, on demand, as with `getContents`.

renameFile :: FilePath -> FilePath -> IO () Source #

``renameFile` old new` changes the name of an existing file system object from old to new. If the new object already exists, it is replaced by the old object. Neither path may refer to an existing directory.

A conformant implementation need not support renaming files in all situations (e.g. renaming across different physical devices), but the constraints must be documented. On Windows, this does not support renaming across different physical devices; if you are looking to do so, consider using `copyFileWithMetadata` and `removeFile`.

On Windows, this calls `MoveFileEx` with `MOVEFILE_REPLACE_EXISTING` set, which is not guaranteed to be atomic (https://github.com/haskell/directory/issues/109).

On other platforms, this operation is atomic.

The operation may fail with:

- `HardwareFault` A physical I/O error has occurred. `[EIO]`
- `InvalidArgument` Either operand is not a valid file name. `[ENAMETOOLONG, ELOOP]`
- `isDoesNotExistError` The original file does not exist, or there is no path to the target. `[ENOENT, ENOTDIR]`
- `isPermissionError` The process has insufficient privileges to perform the operation. `[EROFS, EACCES, EPERM]`
- `isFullError` Insufficient resources are available to perform the operation. `[EDQUOT, ENOSPC, ENOMEM, EMLINK]`
- `UnsatisfiedConstraints` Implementation-dependent constraints are not satisfied. `[EBUSY]`
- `UnsupportedOperation` The implementation does not support renaming in this situation. `[EXDEV]`
- `InappropriateType` Either path refers to an existing directory. `[ENOTDIR, EISDIR, EINVAL, EEXIST, ENOTEMPTY]`