2 | import public System.Posix.File
3 | import public IO.Async.Posix
5 | import System.File.Error
15 | ELift1 World f => Resource f RawMode where
16 | cleanup rm = lift1 (ioToF1 resetRawMode)
20 | toErrno : FileError -> Errno
21 | toErrno (GenericFileError i) = EN (cast i)
22 | toErrno FileReadError = EPERM
23 | toErrno FileWriteError = EPERM
24 | toErrno FileNotFound = ENOENT
25 | toErrno PermissionDenied = EACCES
26 | toErrno FileExists = EEXIST
28 | parameters {auto has : Has Errno es}
33 | fileIO : IO (Either FileError a) -> Async e es a
36 | Left x => throw (toErrno x)
48 | rawMode : Async e es RawMode
49 | rawMode = fileIO enableRawMode $> RM
52 | withFile : String -> Flags -> Mode -> (Fd -> Async e es a) -> Async e es a
53 | withFile pth fs m = use1 (openFile pth fs m)
57 | readFile : (0 r : Type) -> FromBuf r => String -> Bits32 -> Async e es r
58 | readFile r pth buf = withFile pth O_RDONLY 0 $
\fd => read fd r buf
62 | writeFile : ToBuf r => String -> r -> Async e es ()
63 | writeFile pth v = withFile pth O_WRONLY 0 $
\fd => fwrite fd v
67 | createFile : ToBuf r => String -> Mode -> r -> Async e es ()
68 | createFile pth m v = withFile pth create m $
\fd => fwrite fd v
74 | appendFile : ToBuf r => String -> Mode -> r -> Async e es ()
75 | appendFile pth m v = withFile pth append m $
\fd => fwrite fd v