Bugfix: totalUnconsumedBytes works properly within withReadableRange blocks
This commit is contained in:
parent
5d7cad792f
commit
81c24860e2
2 changed files with 13 additions and 2 deletions
|
|
@ -282,8 +282,12 @@ func totalUnconsumedBytes*(s: InputStream): Natural =
|
||||||
## buffers and that can be consumed with `read` or `advance`.
|
## buffers and that can be consumed with `read` or `advance`.
|
||||||
let
|
let
|
||||||
localRunway = s.span.len
|
localRunway = s.span.len
|
||||||
runwayInBuffers = if s.buffers == nil: 0
|
runwayInBuffers = if s.buffers == nil:
|
||||||
else: s.buffers.totalBufferedBytes
|
0
|
||||||
|
elif s.buffers.fauxEofPos != 0:
|
||||||
|
s.buffers.fauxEofPos - s.spanEndPos
|
||||||
|
else:
|
||||||
|
s.buffers.totalBufferedBytes
|
||||||
|
|
||||||
if localRunway == 0 and runwayInBuffers > 0:
|
if localRunway == 0 and runwayInBuffers > 0:
|
||||||
getNewSpan s
|
getNewSpan s
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,9 @@ procSuite "input stream":
|
||||||
test "next returns none":
|
test "next returns none":
|
||||||
check input.next.isNone
|
check input.next.isNone
|
||||||
|
|
||||||
|
emptyInputTests "memoryInput":
|
||||||
|
var input = InputStream()
|
||||||
|
|
||||||
emptyInputTests "unsafeMemoryInput":
|
emptyInputTests "unsafeMemoryInput":
|
||||||
var str = ""
|
var str = ""
|
||||||
var input = unsafeMemoryInput(str)
|
var input = unsafeMemoryInput(str)
|
||||||
|
|
@ -140,12 +143,16 @@ procSuite "input stream":
|
||||||
let s = fileInput(asciiTableFile, pageSize = 100)
|
let s = fileInput(asciiTableFile, pageSize = 100)
|
||||||
if s.readable(20):
|
if s.readable(20):
|
||||||
s.withReadableRange(20, r):
|
s.withReadableRange(20, r):
|
||||||
|
check r.len.get == 20
|
||||||
|
check r.totalUnconsumedBytes == 20
|
||||||
check r.readAll.len == 20
|
check r.readAll.len == 20
|
||||||
|
|
||||||
check s.readable
|
check s.readable
|
||||||
|
|
||||||
if s.readable(200):
|
if s.readable(200):
|
||||||
s.withReadableRange(200, r):
|
s.withReadableRange(200, r):
|
||||||
|
check r.len.get == 200
|
||||||
|
check r.totalUnconsumedBytes == 200
|
||||||
check r.readAll.len == 200
|
check r.readAll.len == 200
|
||||||
|
|
||||||
check s.readable
|
check s.readable
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue