Permalink
Browse files

v0.0.4

  • Loading branch information...
1 parent 8dc8dfe commit d0abaa8af583a4ad7a5f3dded6b5ea6139561298 Gabriel Llamas committed Apr 12, 2012
Showing with 22 additions and 19 deletions.
  1. +1 −1 README.md
  2. +1 −1 build/buffered-reader.js
  3. +1 −1 build/package.json
  4. +18 −15 src/buffered-reader.js
  5. +1 −1 src/package.json
View
@@ -7,7 +7,7 @@ Node BufferedReader
[Availability](#availability) | [Compatibility](#compatibility) | [Documentation](#documentation)
-Version: 0.0.3
+Version: 0.0.4
<a name="availability"></a>
#### Availability [](#start) ####
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3,7 +3,7 @@
"author": {
"name": "Gabriel Llamas"
},
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "Fully configurable buffered reader.",
"repository": {
"type": "git",
View
@@ -5,7 +5,7 @@
* @author Gabriel Llamas
* @created 10/04/2012
* @modified 11/04/2012
- * @version 0.0.3
+ * @version 0.0.4
*/
"use strict";
@@ -35,29 +35,29 @@ var BufferedReader = function (fileName, bufferSize, encoding){
bufferSize = BUFFER_SIZE;
}
- this._stream = FS.createReadStream (getFileName (fileName), {
- bufferSize: bufferSize,
- encoding: encoding
- });
+ this._settings = {
+ encoding: encoding,
+ bufferSize: bufferSize
+ };
- var me = this;
- this._stream.on ("error", function (error){
- me.emit ("error", error);
- });
+ this._fileName = getFileName (fileName);
};
BufferedReader.prototype = Object.create (EVENTS.EventEmitter.prototype);
BufferedReader.prototype.constructor = BufferedReader;
BufferedReader.prototype.read = function (){
+ var stream = FS.createReadStream (this._fileName, this._settings);
+
+ var me = this;
var lastChunk;
var buffer;
var me = this;
var loop = this.listeners ("character").length !== 0 || this.listeners ("line").length !== 0 ||
this.listeners ("byte").length !== 0;
- this._stream.on ("data", function (data){
+ stream.on ("data", function (data){
buffer = data;
var offset = 0;
var chunk;
@@ -67,15 +67,14 @@ BufferedReader.prototype.read = function (){
if (loop){
for (var i=0; i<len; i++){
character = data[i];
- if (me._stream.encoding){
+ if (stream.encoding){
me.emit ("character", character === "\r" ? "\n" : character);
}else{
me.emit ("byte", character);
continue;
}
- var eol = character === "\n" || character === "\r";
- if (eol){
+ if (character === "\n" || character === "\r"){
chunk = data.slice (offset, i);
offset = i + 1;
@@ -92,7 +91,7 @@ BufferedReader.prototype.read = function (){
}
}
- if (me._stream.encoding && offset !== len){
+ if (stream.encoding && offset !== len){
var s = offset === 0 ? data : data.slice (offset);
lastChunk = lastChunk ? lastChunk.concat (s) : s;
}
@@ -101,13 +100,17 @@ BufferedReader.prototype.read = function (){
me.emit ("buffer", data);
});
- this._stream.on ("end", function (){
+ stream.on ("end", function (){
if (loop && lastChunk){
me.emit ("line", lastChunk);
}
me.emit ("end");
});
+
+ stream.on ("error", function (error){
+ me.emit ("error", error);
+ });
};
module.exports.BufferedReader = BufferedReader;
View
@@ -3,7 +3,7 @@
"author": {
"name": "Gabriel Llamas"
},
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "Fully configurable buffered reader.",
"repository": {
"type": "git",

0 comments on commit d0abaa8

Please sign in to comment.