Copyright | (c) Julian Ospald 2023-2024 |
---|---|
License | BSD3 |
Maintainer | hasufell@posteo.de |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module mimics base API wrt file IO, but using OsPath
.
Synopsis
- openBinaryFile :: OsPath -> IOMode -> IO Handle
- withFile :: OsPath -> IOMode -> (Handle -> IO r) -> IO r
- withBinaryFile :: OsPath -> IOMode -> (Handle -> IO r) -> IO r
- withFile' :: OsPath -> IOMode -> (Handle -> IO r) -> IO r
- withBinaryFile' :: OsPath -> IOMode -> (Handle -> IO r) -> IO r
- readFile :: OsPath -> IO ByteString
- readFile' :: OsPath -> IO ByteString
- writeFile :: OsPath -> ByteString -> IO ()
- writeFile' :: OsPath -> ByteString -> IO ()
- appendFile :: OsPath -> ByteString -> IO ()
- appendFile' :: OsPath -> ByteString -> IO ()
- openFile :: OsPath -> IOMode -> IO Handle
- openExistingFile :: OsPath -> IOMode -> IO Handle
- openTempFile :: OsPath -> OsString -> IO (OsPath, Handle)
- openBinaryTempFile :: OsPath -> OsString -> IO (OsPath, Handle)
- openTempFileWithDefaultPermissions :: OsPath -> OsString -> IO (OsPath, Handle)
- openBinaryTempFileWithDefaultPermissions :: OsPath -> OsString -> IO (OsPath, Handle)
Documentation
openBinaryFile :: OsPath -> IOMode -> IO Handle Source #
Like openFile
, but open the file in binary mode.
On Windows, reading a file in text mode (which is the default)
will translate CRLF to LF, and writing will translate LF to CRLF.
This is usually what you want with text files. With binary files
this is undesirable; also, as usual under Microsoft operating systems,
text mode treats control-Z as EOF. Binary mode turns off all special
treatment of end-of-line and end-of-file characters.
(See also hSetBinaryMode
.)
withFile :: OsPath -> IOMode -> (Handle -> IO r) -> IO r Source #
Run an action on a file.
The Handle
is automatically closed afther the action.
withFile' :: OsPath -> IOMode -> (Handle -> IO r) -> IO r Source #
Run an action on a file.
The Handle
is not automatically closed to allow lazy IO. Use this
with caution.
readFile :: OsPath -> IO ByteString Source #
The readFile
function reads a file and returns the contents of the file
as a ByteString
. The file is read lazily, on demand.
readFile' :: OsPath -> IO ByteString Source #
The readFile'
function reads a file and returns the contents of the file
as a ByteString
. The file is fully read before being returned.
writeFile :: OsPath -> ByteString -> IO () Source #
The computation writeFile
file str
function writes the lazy ByteString
str
,
to the file file
.
writeFile' :: OsPath -> ByteString -> IO () Source #
The computation writeFile
file str
function writes the strict ByteString
str
,
to the file file
.
appendFile :: OsPath -> ByteString -> IO () Source #
The computation appendFile
file str
function appends the lazy ByteString
str
,
to the file file
.
appendFile' :: OsPath -> ByteString -> IO () Source #
The computation appendFile
file str
function appends the strict ByteString
str
,
to the file file
.
openExistingFile :: OsPath -> IOMode -> IO Handle Source #
Open an existing file and return the Handle
.
:: OsPath | Directory in which to create the file |
-> OsString | File name template. If the template is "foo.ext" then the created file will be "fooXXX.ext" where XXX is some random number. Note that this should not contain any path separator characters. On Windows, the template prefix may be truncated to 3 chars, e.g. "foobar.ext" will be "fooXXX.ext". |
-> IO (OsPath, Handle) |
The function creates a temporary file in ReadWrite mode. The created file isn't deleted automatically, so you need to delete it manually.
The file is created with permissions such that only the current user can read/write it.
With some exceptions (see below), the file will be created securely
in the sense that an attacker should not be able to cause
openTempFile to overwrite another file on the filesystem using your
credentials, by putting symbolic links (on Unix) in the place where
the temporary file is to be created. On Unix the O_CREAT
and
O_EXCL
flags are used to prevent this attack, but note that
O_EXCL
is sometimes not supported on NFS filesystems, so if you
rely on this behaviour it is best to use local filesystems only.
Since: 0.1.3
openBinaryTempFile :: OsPath -> OsString -> IO (OsPath, Handle) Source #
Like openTempFile
, but opens the file in binary mode. See openBinaryFile
for more comments.
Since: 0.1.3
openTempFileWithDefaultPermissions :: OsPath -> OsString -> IO (OsPath, Handle) Source #
Like openTempFile
, but uses the default file permissions
Since: 0.1.3
openBinaryTempFileWithDefaultPermissions :: OsPath -> OsString -> IO (OsPath, Handle) Source #
Like openBinaryTempFile
, but uses the default file permissions
Since: 0.1.3