nozavroni / csvelte

🕺🏻 CSV and Tabular Data library for PHP
http://phpcsv.com/
Other
6 stars 0 forks source link

Buffer CSVelte\Traits\IsReadable::readLine() #125

Open nozavroni opened 7 years ago

nozavroni commented 7 years ago

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.

nozavroni commented 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.
nozavroni commented 7 years ago

Pushed to v0.2.2 because I can't implement it until I have stream decorators (can but don't want to).