Implement streamed async/sync downloadFile and deprecate old one.

This commit is contained in:
Dominik Picheta 2017-02-11 14:00:53 +01:00
commit f9f86899b5
3 changed files with 62 additions and 16 deletions

View file

@ -476,3 +476,15 @@ proc close*(f: AsyncFile) =
if close(f.fd.cint) == -1:
raiseOSError(osLastError())
proc writeFromStream(f: AsyncFile, fut: FutureStream[string]) {.async.} =
while true:
let (hasValue, value) = await fut.take()
if hasValue:
await f.write(value)
else:
break
proc getWriteStream*(f: AsyncFile): FutureStream[string] =
## Returns a new stream that can be used for writing to the file.
result = newFutureStream[string]()
asyncCheck writeFromStream(f, result)