Comparing version 0.0.7 to 0.0.8
@@ -30,3 +30,3 @@ /** | ||
var self = this; | ||
if (typeof stream === 'string') this.fp = new FileReader(stream); | ||
if (typeof stream === 'string') this.fp = stream = new FileReader(stream); | ||
stream.pause(); | ||
@@ -48,4 +48,5 @@ stream.on('error', function(err) { throw err; }); | ||
else if (this._eof) { | ||
// last line of data is not newline terminated... | ||
// FIXME: return it? discard it? | ||
// end of file is not newline terminated... return it like C fgets() | ||
// note that this is not compatible with newline terminated data | ||
return this._readbuf.slice(this._readoffset, this._readoffset = this._readbuf.length); | ||
} | ||
@@ -71,1 +72,4 @@ else { | ||
}; | ||
// TODO: maybe should decorate the stream: provide an "fgets" method on the stream itself |
{ | ||
"name": "arlib", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Andras' Utility Functions", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -57,7 +57,9 @@ # arlib | ||
synchronous line-at-a-time stream reader. Returns the next buffered line or | ||
the empty string "" if the buffer is currently empty. 3x faster than | ||
require('readline'), and works like C fgets(), it doesn't modify the input. | ||
Note: the caller must periodically yield to allow the buffer to fill. | ||
synchronous line-at-a-time stream reader. Returns the next buffered | ||
line or the empty string "" if the buffer is currently empty. 3x faster | ||
than require('readline'), and works like C fgets(), it doesn't modify | ||
the input. Note: the caller must periodically yield with setImmediate | ||
or setTimeout to allow the buffer to fill. | ||
var fs = require('fs'); | ||
@@ -75,3 +77,6 @@ var Fgets = require('arlib').Fgets; | ||
var contents = ""; | ||
while (!fp.feof()) contents += fp.fgets(); | ||
(function readfile() { | ||
for (var i=0; i<40; i++) contents += fp.fgets(); | ||
if (!fp.feof()) setImmediate(readfile); // yield periodically | ||
})(); | ||
@@ -78,0 +83,0 @@ #### FileReader |
21811
472
89