Skip to content

Instantly share code, notes, and snippets.

@aav
Last active February 6, 2017 22:40
Show Gist options
  • Save aav/f0c1bf47793a2bc2e901228e1078911f to your computer and use it in GitHub Desktop.
Save aav/f0c1bf47793a2bc2e901228e1078911f to your computer and use it in GitHub Desktop.
fun box readFile(auth: AmbientAuth, fname: String): (Array[U8] | FileErrNo) =>
let caps = recover val FileCaps.>set(FileRead).>set(FileStat) end
try
let path = FilePath(auth, fname, caps)
match OpenFile(path)
| let file: File =>
let result = file.read(1024)
file.dispose()
result
| let err: FileErrNo => err
else
FileError // will never happen
end
else
FilePermissionDenied // also unreachable, since FilePath(AmbientAuth, ...) will never raise error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment