diff options
author | Dominik Picheta <dominikpicheta@gmail.com> | 2017-03-23 21:34:53 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@gmail.com> | 2017-03-23 21:34:53 +0100 |
commit | 0cad2896ae7aa7d9b2561785f9243ceb546abf99 (patch) | |
tree | e00ce424b8687289ee7d728522d9ec03657e12f5 /lib | |
parent | f2ca6021dc3dae51d98fbe830c1590b675522800 (diff) | |
download | Nim-0cad2896ae7aa7d9b2561785f9243ceb546abf99.tar.gz |
Implement asyncfile.readToStream.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/asyncfile.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/asyncfile.nim b/lib/pure/asyncfile.nim index 488b8276e..c58e6c11b 100644 --- a/lib/pure/asyncfile.nim +++ b/lib/pure/asyncfile.nim @@ -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() \ No newline at end of file |