Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "readline", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Simple streaming readline module.", | ||
@@ -5,0 +5,0 @@ "main": "readline.js", |
@@ -17,6 +17,7 @@ var fs = require('fs'), | ||
lineCount = 0, | ||
emit = function(line, count) { | ||
self.emit('line', new Buffer(line).toString(), count); | ||
byteCount = 0, | ||
emit = function(line, lineCount, byteCount) { | ||
self.emit('line', new Buffer(line).toString(), lineCount, byteCount); | ||
}; | ||
this.input = fs.createReadStream(file); | ||
this.input = fs.createReadStream(file, opts); | ||
this.input.on('open', function(fd) { | ||
@@ -27,5 +28,6 @@ self.emit('open', fd); | ||
for (var i = 0; i < data.length; i++) { | ||
byteCount++; | ||
if (0 <= newlines.indexOf(data[i])) { // Newline char was found. | ||
lineCount++; | ||
if (line.length) emit(line, lineCount); | ||
if (line.length) emit(line, lineCount, byteCount); | ||
line = []; // Empty buffer. | ||
@@ -44,3 +46,3 @@ } else { | ||
lineCount++; | ||
emit(line, lineCount); | ||
emit(line, lineCount, byteCount); | ||
} | ||
@@ -47,0 +49,0 @@ self.emit('end'); |
@@ -29,3 +29,3 @@ ## _readline_ | ||
rl = readline('./somefile.txt'); | ||
rl.on('line', function(line) { | ||
rl.on('line', function(line, lineCount, byteCount) { | ||
// do something with the line of text | ||
@@ -32,0 +32,0 @@ }) |
@@ -0,3 +1,5 @@ | ||
var fs = require('fs'); | ||
var readLine = require('../readline.js'); | ||
var test = require("tap").test; | ||
var readLine = require('../readline.js'); | ||
test("test reading lines",function(t){ | ||
@@ -63,1 +65,14 @@ console.error("reading large file line by line asserts may take a while"); | ||
test("byte count", function(t){ | ||
var rl = readLine('./fixtures/nmbr.txt'); | ||
var expect = fs.statSync('./fixtures/nmbr.txt').size; | ||
var actual = 0; | ||
rl.on("line", function (line, ln, byteCount){ | ||
console.log("byte count",byteCount); | ||
actual=byteCount; | ||
}); | ||
rl.on("end", function (){ | ||
t.ok(actual === expect,"byte count is correct"); | ||
t.end(); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1955783
117
3