diff --git a/faststreams/inputs.nim b/faststreams/inputs.nim index e7b36bb..5dc051b 100644 --- a/faststreams/inputs.nim +++ b/faststreams/inputs.nim @@ -808,13 +808,10 @@ template readIntoExImpl(s: InputStream, let totalBytesDrained = drainBuffersInto(s, dst, dstLen) var bytesDeficit = (dstLen - totalBytesDrained) - if bytesDeficit > 0: + if bytesDeficit > 0 and s.vtable != nil: var adjustedDst = offset(dst, totalBytesDrained) while true: - if s.vtable.isNil(): - break - let newBytesRead = awaiter s.vtable.readOp(s, adjustedDst, bytesDeficit) s.spanEndPos += newBytesRead diff --git a/tests/test_outputs.nim b/tests/test_outputs.nim index 86a3fbc..4ce3f0f 100644 --- a/tests/test_outputs.nim +++ b/tests/test_outputs.nim @@ -20,10 +20,12 @@ proc repeat(b: byte, count: int): seq[byte] = result = newSeq[byte](count) for i in 0 ..< count: result[i] = b +const line = "123456789123456789123456789123456789\n\n\n\n\n" + proc randomBytes(n: int): seq[byte] = result.newSeq n for i in 0 ..< n: - result[i] = byte(rand(int('1')..int('9'))) + result[i] = byte(rand(line)) proc readAllAndClose(s: InputStream): seq[byte] = while s.readable: @@ -53,8 +55,8 @@ suite "output stream": streamWritingToExistingBuffer = unsafeMemoryOutput(buffer, bufferSize) teardown: - fileStream.close() - unbufferedFileStream.close() + close fileStream + close unbufferedFileStream removeFile fileOutputPath removeFile unbufferedFileOutputPath dealloc buffer