openClose(path: Text) (ok: Bool) { file = dever.io.open(path) alias = file dever.io.close(alias) ok = true } readBytes(path: Text, limit: Int) (bytes: Bytes) { file = dever.io.open(path) bytes = unpack(dever.io.read(file, limit)) dever.io.close(file) } unpack(state: dever.io.ReadState.Read(value)) (bytes: Bytes) { bytes = value } unpack(state: dever.io.ReadState.End) (bytes: Bytes) { bytes = dever.bytes.fromText("") } consume(path: Text, limit: Int) (total: Int) { file = dever.io.open(path) stream = dever.io.chunks(file, limit) total = reduce(count, stream, 0) dever.io.close(file) } resume(path: Text, limit: Int) (total: Int) { file = dever.io.open(path) stream = dever.io.chunks(file, limit) alias = stream head = reduceUntil(take, stream, 0) total = reduce(count, alias, head) close(stream) close(alias) dever.io.close(file) } closedStream(path: Text) (total: Int) { file = dever.io.open(path) stream = dever.io.chunks(file, 64) dever.io.close(file) total = reduce(count, stream, 0) } count(event: dever.io.ReadEvent.Chunk(bytes), state: Int) (total: Int) { total = reduce(add, bytes, state) } count(event: dever.io.ReadEvent.Failed(message), state: Int) (total: Int) { fail(dever.io.ReadEvent.Failed(message)) } add(item: Int, state: Int) (total: Int) { total = state + item } take(event: dever.io.ReadEvent, state: Int) (total: Int, stop: Bool) { total = count(event, state) stop = true }