mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
30 lines
548 B
Text
30 lines
548 B
Text
module [line!, withOpen!, chunk!, Handle]
|
|
|
|
import pf.Host
|
|
|
|
Handle := U64
|
|
|
|
line! : Handle => Str
|
|
line! = \@Handle handle ->
|
|
Host.getFileLine! handle
|
|
|
|
chunk! : Handle => List U8
|
|
chunk! = \@Handle handle ->
|
|
Host.getFileBytes! handle
|
|
|
|
open! : Str => Handle
|
|
open! = \path ->
|
|
Host.openFile! path
|
|
|> @Handle
|
|
|
|
close! : Handle => {}
|
|
close! = \@Handle handle ->
|
|
Host.closeFile! handle
|
|
|
|
withOpen! : Str, (Handle => a) => a
|
|
withOpen! = \path, callback! ->
|
|
handle = open! path
|
|
result = callback! handle
|
|
close! handle
|
|
|
|
result
|