summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2017-03-23 21:34:53 +0100
committerDominik Picheta <dominikpicheta@gmail.com>2017-03-23 21:34:53 +0100
commit0cad2896ae7aa7d9b2561785f9243ceb546abf99 (patch)
treee00ce424b8687289ee7d728522d9ec03657e12f5 /lib
parentf2ca6021dc3dae51d98fbe830c1590b675522800 (diff)
downloadNim-0cad2896ae7aa7d9b2561785f9243ceb546abf99.tar.gz
Implement asyncfile.readToStream.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/asyncfile.nim10
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
n11' href='#n11'>11
12
13
14
15
16
17