added streams.readAll proc

This commit is contained in:
Araq
2015-09-28 16:39:52 +02:00
parent d8a10457e2
commit 985594cbb8

View File

@@ -101,6 +101,18 @@ proc readData*(s: Stream, buffer: pointer, bufLen: int): int =
## low level proc that reads data into an untyped `buffer` of `bufLen` size.
result = s.readDataImpl(s, buffer, bufLen)
proc readAll*(s: Stream): string =
## Reads all available data.
result = newString(1000)
var r = 0
while true:
let readBytes = readData(s, addr(result[r]), 1000)
if readBytes < 1000:
setLen(result, r+readBytes)
break
inc r, 1000
setLen(result, r+1000)
proc readData*(s, unused: Stream, buffer: pointer,
bufLen: int): int {.deprecated.} =
## low level proc that reads data into an untyped `buffer` of `bufLen` size.