New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

linebyline

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linebyline - npm Package Compare versions

Comparing version

to
0.0.8

5

package.json
{
"name": "linebyline",
"version": "0.0.7",
"description": "Simple streaming readline module.",
"version": "0.0.8",
"description": "Simple streaming readline module. Reads a file line by line. Previously under readline",
"main": "readline.js",

@@ -16,2 +16,3 @@ "scripts": {

"readline",
"line by line",
"file"

@@ -18,0 +19,0 @@ ],

@@ -17,4 +17,5 @@ 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);
};

@@ -27,5 +28,6 @@ this.input = fs.createReadStream(file);

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');

2

README.md

@@ -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();
});
});