Implement asyncfile.readToStream.

This commit is contained in:
Dominik Picheta
2017-03-23 21:34:53 +01:00
parent f2ca6021dc
commit 0cad2896ae

View File

@@ -489,3 +489,13 @@ proc writeFromStream*(f: AsyncFile, fs: FutureStream[string]) {.async.} =
await f.write(value)
else:
break
proc readToStream*(f: AsyncFile, fs: FutureStream[string]) {.async.} =
## Writes data to the specified future stream as the file is read.
while true:
let data = await read(f, 4000)
if data.len == 0:
break
await fs.write(data)
fs.complete()