| 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 #
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 #
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 () #
changes the name of an existing file system
object from old to new. If the new object already
exists, it is atomically 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.renameFile old new
The operation may fail with:
HardwareFaultA physical I/O error has occurred.[EIO]InvalidArgumentEither operand is not a valid file name.[ENAMETOOLONG, ELOOP]isDoesNotExistErrorThe original file does not exist, or there is no path to the target.[ENOENT, ENOTDIR]isPermissionErrorThe process has insufficient privileges to perform the operation.[EROFS, EACCES, EPERM]isFullErrorInsufficient resources are available to perform the operation.[EDQUOT, ENOSPC, ENOMEM, EMLINK]UnsatisfiedConstraintsImplementation-dependent constraints are not satisfied.[EBUSY]UnsupportedOperationThe implementation does not support renaming in this situation.[EXDEV]InappropriateTypeEither path refers to an existing directory.[ENOTDIR, EISDIR, EINVAL, EEXIST, ENOTEMPTY]