Implement InputStream.nonBlockingReads and document it
This commit is contained in:
parent
fc76250d02
commit
ec5c3af313
3 changed files with 56 additions and 0 deletions
|
|
@ -20,6 +20,10 @@ proc countLines(s: InputStream): Natural =
|
|||
for s in lines(s):
|
||||
inc result
|
||||
|
||||
proc readAll(s: InputStream): seq[byte] =
|
||||
while s.readable:
|
||||
result.add s.read
|
||||
|
||||
const
|
||||
asciiTableFile = "files" / "ascii_table.txt"
|
||||
asciiTableContents = slurp(asciiTableFile)
|
||||
|
|
@ -132,6 +136,13 @@ procSuite "input stream":
|
|||
|
||||
check not fileExists(fileName)
|
||||
|
||||
test "non-blocking reads":
|
||||
let s = fileInput(asciiTableFile, pageSize = 20)
|
||||
if s.readable:
|
||||
s.nonBlockingReads:
|
||||
check s.readAll.len == 20
|
||||
check s.readable
|
||||
|
||||
test "simple":
|
||||
var input = repeat("1234 5678 90AB CDEF\n", 1000)
|
||||
var stream = unsafeMemoryInput(input)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue