Skip to content
Browse files

v0.0.3

  • Loading branch information...
1 parent 636206d commit f7db036fceeddf18ffb43bb8c054174e37071578 @gagle committed
Showing with 8 additions and 8 deletions.
  1. +1 −1 build/buffered-reader.js
  2. +1 −1 build/package.json
  3. +5 −5 src/buffered-reader.js
  4. +1 −1 src/package.json
View
2 build/buffered-reader.js
@@ -1 +1 @@
-"use strict";var EVENTS=require("events"),FS=require("fs"),PATH=require("path"),BUFFER_SIZE=16384,SLASH=PATH.normalize("/"),getFileName=function(a){var b=process.mainModule.filename,c=b.substring(0,b.lastIndexOf(SLASH)),d=PATH.relative(process.cwd(),c);return PATH.join(d,a)},BufferedReader=function(a,b,c){EVENTS.EventEmitter.call(this);var d=arguments.length;d===1?(b=BUFFER_SIZE,c=null):d===2&&typeof b=="string"&&(c=b,b=BUFFER_SIZE),this._stream=FS.createReadStream(getFileName(a),{bufferSize:b,encoding:c});var e=this;this._stream.on("error",function(a){e.emit("error",a)})};BufferedReader.prototype=Object.create(EVENTS.EventEmitter.prototype),BufferedReader.prototype.constructor=BufferedReader,BufferedReader.prototype.read=function(){var a,b,c=this,d=this.listeners("character").length!==0||this.listeners("line").length!==0||this.listeners("byte").length!==0;this._stream.on("data",function(e){b=e;var f=0,g,h,i=e.length;if(d){for(var j=0;j<i;j++){h=e[j];if(!c._stream.encoding){c.emit("byte",h);continue}c.emit("character",h);var k=h==="\n"||h==="\r";k&&(g=e.slice(f,j++),f=j,a&&(g=a.concat(g),a=null),j+1!==i&&h==="\r"&&e[j+1]==="\n"&&j++,c.emit("line",g))}if(c._stream.encoding&&f!==i){var l=f===0?e:e.slice(f);a=a?a.concat(l):l}}c.emit("buffer",e)}),this._stream.on("end",function(){d&&a&&c.emit("line",a),c.emit("end")})},module.exports.BufferedReader=BufferedReader;
+"use strict";var EVENTS=require("events"),FS=require("fs"),PATH=require("path"),BUFFER_SIZE=16384,SLASH=PATH.normalize("/"),getFileName=function(a){var b=process.mainModule.filename,c=b.substring(0,b.lastIndexOf(SLASH)),d=PATH.relative(process.cwd(),c);return PATH.join(d,a)},BufferedReader=function(a,b,c){EVENTS.EventEmitter.call(this);var d=arguments.length;d===1?(b=BUFFER_SIZE,c=null):d===2&&typeof b=="string"&&(c=b,b=BUFFER_SIZE),this._stream=FS.createReadStream(getFileName(a),{bufferSize:b,encoding:c});var e=this;this._stream.on("error",function(a){e.emit("error",a)})};BufferedReader.prototype=Object.create(EVENTS.EventEmitter.prototype),BufferedReader.prototype.constructor=BufferedReader,BufferedReader.prototype.read=function(){var a,b,c=this,d=this.listeners("character").length!==0||this.listeners("line").length!==0||this.listeners("byte").length!==0;this._stream.on("data",function(e){b=e;var f=0,g,h,i=e.length;if(d){for(var j=0;j<i;j++){h=e[j];if(!c._stream.encoding){c.emit("byte",h);continue}c.emit("character",h==="\r"?"\n":h);var k=h==="\n"||h==="\r";k&&(g=e.slice(f,j),f=j+1,a&&(g=a.concat(g),a=null),j+1!==i&&h==="\r"&&e[j+1]==="\n"&&j++,c.emit("line",g))}if(c._stream.encoding&&f!==i){var l=f===0?e:e.slice(f);a=a?a.concat(l):l}}c.emit("buffer",e)}),this._stream.on("end",function(){d&&a&&c.emit("line",a),c.emit("end")})},module.exports.BufferedReader=BufferedReader;
View
2 build/package.json
@@ -3,7 +3,7 @@
"author": {
"name": "Gabriel Llamas"
},
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "Fully configurable buffered reader.",
"repository": {
"type": "git",
View
10 src/buffered-reader.js
@@ -5,7 +5,7 @@
* @author Gabriel Llamas
* @created 10/04/2012
* @modified 11/04/2012
- * @version 0.0.2
+ * @version 0.0.3
*/
"use strict";
@@ -68,7 +68,7 @@ BufferedReader.prototype.read = function (){
for (var i=0; i<len; i++){
character = data[i];
if (me._stream.encoding){
- me.emit ("character", character);
+ me.emit ("character", character === "\r" ? "\n" : character);
}else{
me.emit ("byte", character);
continue;
@@ -76,15 +76,15 @@ BufferedReader.prototype.read = function (){
var eol = character === "\n" || character === "\r";
if (eol){
- chunk = data.slice (offset, i++);
- offset = i;
+ chunk = data.slice (offset, i);
+ offset = i + 1;
if (lastChunk){
chunk = lastChunk.concat (chunk);
lastChunk = null;
}
- if (i+1 !== len && character === "\r" && data[i+1] === "\n"){
+ if (i + 1 !== len && character === "\r" && data[i + 1] === "\n"){
i++;
}
View
2 src/package.json
@@ -3,7 +3,7 @@
"author": {
"name": "Gabriel Llamas"
},
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "Fully configurable buffered reader.",
"repository": {
"type": "git",

0 comments on commit f7db036

Please sign in to comment.
Something went wrong with that request. Please try again.