Abstract interface for performing file I/O
- User-supplied buffers
For functions that require user-supplied buffers (i.e.,
), it is the user's responsiblity to provide buffers that are large enough. Behaviour is undefined if the I/O operations access the buffer outside it's allocated range.
Constructors
HasFSdumpState :: m StringDebugging: human-readable description of file system state
hOpen :: HasCallStack => FsPath -> OpenMode -> m (Handle h)Open a file
hClose :: HasCallStack => Handle h -> m ()Close a file
hIsOpen :: HasCallStack => Handle h -> m BoolIs the handle open?
hSeek :: HasCallStack => Handle h -> SeekMode -> Int64 -> m ()hGetSome :: HasCallStack => Handle h -> Word64 -> m ByteStringTry to read
nbytes from a handleWhen at the end of the file, an empty bytestring will be returned.
The returned bytestring will typically have length
n, but may be shorter in case of a partial read, see #277. However, a partial read will always return at least 1 byte, as returning 0 bytes would mean that we have reached EOF.Postcondition: for the length of the returned bytestring
bswe havelength bs >= 0andlength bs <= n.hGetSomeAt :: HasCallStack => Handle h -> Word64 -> AbsOffset -> m ByteStringSame as hGetSome, but does not affect the file offset. An additional argument is used to specify the offset. This allows it to be called concurrently for the same file handle. However, the actual level of parallelism achieved depends on the implementation and the operating system: generally on Unix it will be "more parallel" than on Windows.
hPutSome :: HasCallStack => Handle h -> ByteString -> m Word64Write to a handle
The return value indicates the number of bytes written and will typically be equal to
l, the length of the bytestring, but may be shorter in case of a partial write, see #277.If nothing can be written at all, an exception will be thrown.
Postcondition: the return value
nisn > 0andn <= l, unless the given bytestring is empty, in which casencan be 0.hTruncate :: HasCallStack => Handle h -> Word64 -> m ()Truncate the file to the specified size
NOTE: Only supported in append mode.
hGetSize :: HasCallStack => Handle h -> m Word64Return current file size
NOTE: This is not thread safe (changes made to the file in other threads may affect this thread).
createDirectory :: HasCallStack => FsPath -> m ()Create new directory
createDirectoryIfMissing :: HasCallStack => Bool -> FsPath -> m ()Create new directory if it doesn't exist.
createDirectoryIfMissing Truewill also try to create all parent dirs.listDirectory :: HasCallStack => FsPath -> m (Set String)List contents of a directory
doesDirectoryExist :: HasCallStack => FsPath -> m BoolCheck if the path exists and is a directory
doesFileExist :: HasCallStack => FsPath -> m BoolCheck if the path exists and is a file
removeDirectoryRecursive :: HasCallStack => FsPath -> m ()Remove the directory (which must exist) and its contents
removeFile :: HasCallStack => FsPath -> m ()Remove the file (which must exist)
renameFile :: HasCallStack => FsPath -> FsPath -> m ()Rename the file (which must exist) from the first path to the second path. If there is already a file at the latter path, it is replaced by the new one.
NOTE: only works for files within the same folder.
mkFsErrorPath :: FsPath -> FsErrorPathUseful for better error reporting
unsafeToFilePath :: FsPath -> m FilePathhGetBufSome :: HasCallStack => Handle h -> MutableByteArray (PrimState m) -> BufferOffset -> ByteCount -> m ByteCountLike hGetSome, but the bytes are read into a user-supplied buffer. See User-supplied buffers.
hGetBufSomeAt :: HasCallStack => Handle h -> MutableByteArray (PrimState m) -> BufferOffset -> ByteCount -> AbsOffset -> m ByteCountLike hGetSomeAt, but the bytes are read into a user-supplied buffer. See User-supplied buffers.
hPutBufSome :: HasCallStack => Handle h -> MutableByteArray (PrimState m) -> BufferOffset -> ByteCount -> m ByteCountLike hPutSome, but the bytes are written from a user-supplied buffer. See User-supplied buffers.
hPutBufSomeAt :: HasCallStack => Handle h -> MutableByteArray (PrimState m) -> BufferOffset -> ByteCount -> AbsOffset -> m ByteCountLike hPutSome, but the bytes are written from a user-supplied buffer at a given file offset. This offset does not affect the offset stored in the file handle (see also hGetSomeAt). See User-supplied buffers.