Open nozavroni opened 7 years ago
In order to do this properly I think I'm going to need to write yet another type of Streamable
class. It needs to basically use BufferStream without interfering with a regular Stream's read() and seek()/tell() methods. So it would do this:
$stream = Stream::open("./data/products.csv", 'r+b');
$wrapper = new BufferWrapStream($stream); // not really sure what to call it
// internally it would be doing this...
$buffer = new BufferStream();
$buffer->write($stream->read(8192));
// and then when you call the wrapper's tell() method...
echo $wrapper->tell(); // prints "0"
// it still says 0 because although you have read up to 8192 bytes from the stream, the wrapper
// hasn't had jack shiznit read from it.
Pushed to v0.2.2 because I can't implement it until I have stream decorators (can but don't want to).
Right now the
CSVelte\Traits\IsReadable::readLine()
method performs its I/O one character at a time. Rather than doing a whole bunch of one-character read operations, perform one large read operation, buffer it, and then read from the buffer a character at a time. This will be much better I/O, performance and memory-wise.