Address review comments; Add documentation; Shared buffering mechanism for input and output streams

This commit is contained in:
Zahary Karadjov 2020-04-29 21:19:18 +03:00
commit b24300bd3f
No known key found for this signature in database
GPG key ID: C8936F8A3073D609
24 changed files with 2396 additions and 1060 deletions

36
tests/test_inputs.nim Normal file
View file

@ -0,0 +1,36 @@
{.used.}
import
os, unittest, strutils, stew/ranges/ptr_arith,
../faststreams
suite "input stream":
test "empty input":
var str = ""
var i = unsafeMemoryInput(str)
check:
i.readable == false
i.next.isNone
expect Defect:
echo i.read
test "missing file input":
const fileName = "there-is-no-such-faststreams-file-1"
check not fileExists(fileName)
expect CatchableError: discard fileInput(fileName)
check not fileExists(fileName)
expect CatchableError: discard memFileInput(fileName)
check not fileExists(fileName)
test "simple":
var input = repeat("1234 5678 90AB CDEF\n", 1000)
var stream = unsafeMemoryInput(input)
check:
(stream.read(4) == "1234".toOpenArrayByte(0, 3))