stream: fix error when reading less than buffer
Function fromList checked if n (number of bytes to be read) was equal to buf.length. However it should check agains str.length, as buf is an array containing buffers from seperate readings of file. This can cause an error when size in readable.read() is less than highWaterMark.
Example: highWaterMark === 10, readable.read(6)
On first read()
, it reads 6 bytes, 4 are left in the buffer. On second read()
, 10 more bytes are read into the buffer. buf
is now an array with two buffers, length 4 and 10. Function adds the first buffer to ret
, n
is now 2. On the second run n === 2 === buf.length
. Fucntion adds all 10 bytes to ret
(which is now 14 bytes long) and removes both entries from state
. state.buffer === []
, state.length === 14
. On the next run, an error occurs as there is nothing to be read from state
, even though there should be.