2021-08-30 17:31:37 +03:00
|
|
|
module System.File.Mode
|
|
|
|
|
|
|
|
import System.Info
|
|
|
|
|
|
|
|
%default total
|
|
|
|
|
2021-10-29 19:58:29 +03:00
|
|
|
||| The different modes a file can be opened.
|
2021-08-30 17:31:37 +03:00
|
|
|
public export
|
|
|
|
data Mode = Read | WriteTruncate | Append | ReadWrite | ReadWriteTruncate | ReadAppend
|
|
|
|
|
2021-10-29 19:58:29 +03:00
|
|
|
||| Convert a file `Mode` to the OS-appropriate string representation.
|
2021-08-30 17:31:37 +03:00
|
|
|
export
|
|
|
|
modeStr : Mode -> String
|
|
|
|
modeStr Read = if isWindows then "rb" else "r"
|
|
|
|
modeStr WriteTruncate = if isWindows then "wb" else "w"
|
|
|
|
modeStr Append = if isWindows then "ab" else "a"
|
|
|
|
modeStr ReadWrite = if isWindows then "rb+" else "r+"
|
|
|
|
modeStr ReadWriteTruncate = if isWindows then "wb+" else "w+"
|
|
|
|
modeStr ReadAppend = if isWindows then "ab+" else "a+"
|