slice-file
Advanced tools
Comparing version 0.2.1 to 1.0.0
56
index.js
var fs = require('fs'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var inherits = require('inherits'); | ||
var split = require('split'); | ||
var split = require('split2'); | ||
@@ -24,2 +24,4 @@ var nextTick = typeof setImmediate === 'function' | ||
fa.emit('open', fd) | ||
for (var i = 0; i < fa._onopen.length; i++) fa._onopen[i](); | ||
fa._onopen.splice(0); | ||
}); | ||
@@ -36,2 +38,3 @@ } | ||
this.mode = opts.mode; | ||
this._onopen = []; | ||
} | ||
@@ -41,7 +44,4 @@ | ||
FA.prototype._read = function (start, end, cb, rev) { | ||
FA.prototype._read = onopen(function (start, end, cb, rev) { | ||
var self = this; | ||
if (self.fd === undefined) { | ||
return self.once('open', self._read.bind(self, start, end, cb, rev)); | ||
} | ||
if (start === undefined) start = 0; | ||
@@ -123,3 +123,3 @@ if (start < 0) return self._readReverse(start, end, cb, rev); | ||
})(); | ||
}; | ||
}); | ||
@@ -137,9 +137,4 @@ FA.prototype._stat = function (cb) { | ||
FA.prototype._readReverse = function (start, end, cb, rev) { | ||
FA.prototype._readReverse = onopen(function (start, end, cb, rev) { | ||
var self = this; | ||
if (self.fd === undefined) { | ||
return self.once('open', function () { | ||
self._readReverse(start, end, cb, rev); | ||
}); | ||
} | ||
if (self.stat === undefined) { | ||
@@ -195,3 +190,3 @@ return self._stat(function (err) { | ||
} | ||
else if (lines.length) { | ||
else if (lines && lines.length) { | ||
cb(null, Buffer(lines[0])); | ||
@@ -255,3 +250,3 @@ } | ||
})(); | ||
}; | ||
}); | ||
@@ -274,3 +269,3 @@ FA.prototype.slice = function (start, end, cb) { | ||
if (err) return tr.emit('error', err); | ||
else tr.queue(line) | ||
else tr.push(line) | ||
@@ -299,3 +294,3 @@ if (cb && line === null) cb(null, res) | ||
if (err) return tr.emit('error', err); | ||
else tr.queue(line) | ||
else tr.push(line) | ||
@@ -338,7 +333,8 @@ if (cb && line === null) cb(null, res) | ||
slice.pipe(tr, { end: false }); | ||
self.once('close', function () { tr.queue(null) }); | ||
tr.once('close', function () { tr.queue(null) }); | ||
self.once('close', function () { tr.push(null) }); | ||
tr.once('close', function () { tr.push(null) }); | ||
var out = tr.pipe(split()).pipe(through(function (line) { | ||
this.queue(line + '\n'); | ||
var out = tr.pipe(split()).pipe(through(function (line, _, next) { | ||
if (line.length) this.push(line + '\n'); | ||
next(); | ||
})); | ||
@@ -358,3 +354,2 @@ tr.on('error', function (err) { out.emit('error', err) }); | ||
var stream = fs.createReadStream(self.file, { | ||
//fd: self.fd, | ||
start: lastStat.size, | ||
@@ -379,8 +374,19 @@ flags: self.flags, | ||
FA.prototype.close = function () { | ||
FA.prototype.close = onopen(function () { | ||
var self = this; | ||
if (self.fd === undefined) return self.once('open', self.close); | ||
fs.close(self.fd, function () { | ||
self.emit('close'); | ||
}); | ||
}; | ||
}); | ||
function onopen (f) { | ||
return function () { | ||
var self = this, args = arguments; | ||
if (self.fd === undefined) { | ||
self._onopen.push(function () { | ||
f.apply(self, args); | ||
}); | ||
} | ||
else return f.apply(self, args); | ||
} | ||
} |
{ | ||
"name": "slice-file", | ||
"version": "0.2.1", | ||
"description": "stream file slices by line number indexes", | ||
"main": "index.js", | ||
"dependencies": { | ||
"inherits": "~1.0.0", | ||
"through": "~2.2.7", | ||
"split": "~0.2.1" | ||
}, | ||
"devDependencies": { | ||
"tap": "~0.4.0" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/substack/slice-file.git" | ||
}, | ||
"homepage": "https://github.com/substack/slice-file", | ||
"keywords": [ | ||
"slice", | ||
"file", | ||
"tail", | ||
"head", | ||
"line", | ||
"number", | ||
"index", | ||
"fs" | ||
], | ||
"author": { | ||
"name": "James Halliday", | ||
"email": "mail@substack.net", | ||
"url": "http://substack.net" | ||
}, | ||
"license": "MIT" | ||
"name": "slice-file", | ||
"version": "1.0.0", | ||
"description": "stream file slices by line number indexes", | ||
"main": "index.js", | ||
"dependencies": { | ||
"inherits": "~1.0.0", | ||
"split2": "^0.2.1", | ||
"through2": "^0.6.5" | ||
}, | ||
"devDependencies": { | ||
"tap": "^0.7.1" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/substack/slice-file.git" | ||
}, | ||
"homepage": "https://github.com/substack/slice-file", | ||
"keywords": [ | ||
"slice", | ||
"file", | ||
"tail", | ||
"head", | ||
"line", | ||
"number", | ||
"index", | ||
"fs" | ||
], | ||
"author": { | ||
"name": "James Halliday", | ||
"email": "mail@substack.net", | ||
"url": "http://substack.net" | ||
}, | ||
"license": "MIT" | ||
} |
var test = require('tap').test; | ||
var sf = require('../'); | ||
var fs = require('fs'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
@@ -15,3 +15,3 @@ var file = __dirname + '/data/follow.txt'; | ||
var res = []; | ||
xs.follow(-3).pipe(through(function (line) { | ||
xs.follow(-3).pipe(through(function (line, _, next) { | ||
res.push(String(line)); | ||
@@ -59,3 +59,4 @@ if (res.length === 3) { | ||
} | ||
next(); | ||
})); | ||
}); |
var test = require('tap').test; | ||
var sf = require('../'); | ||
var fs = require('fs'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
@@ -15,3 +15,3 @@ var file = __dirname + '/data/follow.txt'; | ||
var res = []; | ||
xs.follow(-3).pipe(through(function (line) { | ||
xs.follow(-3).pipe(through(function (line, _, next) { | ||
res.push(String(line)); | ||
@@ -59,3 +59,4 @@ if (res.length === 3) { | ||
} | ||
next(); | ||
})); | ||
}); |
var test = require('tap').test; | ||
var sf = require('../'); | ||
var fs = require('fs'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
@@ -15,3 +15,3 @@ var file = __dirname + '/data/follow.txt'; | ||
var res = []; | ||
xs.follow(-3).pipe(through(function (line) { | ||
xs.follow(-3).pipe(through(function (line, _, next) { | ||
res.push(String(line)); | ||
@@ -45,3 +45,4 @@ if (res.length === 3) { | ||
} | ||
next(); | ||
})); | ||
}); |
var test = require('tap').test; | ||
var lf = require('../'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var fs = require('fs'); | ||
@@ -19,3 +19,3 @@ | ||
s.slice(n).pipe(through(write, end)); | ||
function write (buf) { xs.push(String(buf)) } | ||
function write (buf, _, next) { xs.push(String(buf)); next() } | ||
function end () { | ||
@@ -22,0 +22,0 @@ t.deepEqual(lines.slice(n), xs); |
var test = require('tap').test; | ||
var lf = require('../'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var fs = require('fs'); | ||
@@ -14,3 +14,3 @@ var wordFile = __dirname + '/data/words'; | ||
s.pipe(through(write, end)); | ||
function write (buf) { res.push(String(buf)) } | ||
function write (buf, _, next) { res.push(String(buf)); next() } | ||
function end () { | ||
@@ -37,5 +37,6 @@ t.deepEqual(res, [ | ||
function write (line) { | ||
function write (line, _, next) { | ||
t.ok(Buffer.isBuffer(line)); | ||
res.push(String(line)); | ||
next(); | ||
} | ||
@@ -87,3 +88,2 @@ | ||
var n = slices.shift(); | ||
console.log('n=' + n); | ||
var res = []; | ||
@@ -93,4 +93,5 @@ | ||
function write (line) { | ||
function write (line, _, next) { | ||
res.push(String(line).trim()); | ||
next(); | ||
} | ||
@@ -97,0 +98,0 @@ |
var test = require('tap').test; | ||
var lf = require('../'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var fs = require('fs'); | ||
@@ -15,5 +15,6 @@ var wordFile = __dirname + '/data/words'; | ||
function write (line) { | ||
function write (line, _, next) { | ||
t.ok(Buffer.isBuffer(line)); | ||
res.push(String(line)); | ||
next(); | ||
} | ||
@@ -49,3 +50,2 @@ | ||
var n = amounts.shift(); | ||
console.log('n=' + n); | ||
var res = []; | ||
@@ -55,4 +55,5 @@ | ||
function write (line) { | ||
function write (line, _, next) { | ||
res.push(String(line).trim()); | ||
next(); | ||
} | ||
@@ -59,0 +60,0 @@ |
var test = require('tap').test; | ||
var lf = require('../'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var fs = require('fs'); | ||
@@ -14,3 +14,3 @@ var wordFile = __dirname + '/data/words'; | ||
s.pipe(through(write, end)); | ||
function write (buf) { res.push(String(buf)) } | ||
function write (buf, _, next) { res.push(String(buf)); next() } | ||
function end () { | ||
@@ -31,5 +31,6 @@ t.deepEqual(res, [ | ||
function write (line) { | ||
function write (line, _, next) { | ||
t.ok(Buffer.isBuffer(line)); | ||
res.push(String(line)); | ||
next(); | ||
} | ||
@@ -81,3 +82,2 @@ | ||
var n = slices.shift(); | ||
console.log('n=' + n); | ||
var res = []; | ||
@@ -87,4 +87,5 @@ | ||
function write (line) { | ||
function write (line, _, next) { | ||
res.push(String(line).trim()); | ||
next(); | ||
} | ||
@@ -91,0 +92,0 @@ |
var test = require('tap').test; | ||
var lf = require('../'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var fs = require('fs'); | ||
@@ -15,5 +15,6 @@ var wordFile = __dirname + '/data/words'; | ||
function write (line) { | ||
function write (line, _, next) { | ||
t.ok(Buffer.isBuffer(line)); | ||
res.push(String(line)); | ||
next(); | ||
} | ||
@@ -54,4 +55,5 @@ | ||
function write (line) { | ||
function write (line, _, next) { | ||
res.push(String(line).trim()); | ||
next(); | ||
} | ||
@@ -58,0 +60,0 @@ |
var test = require('tap').test; | ||
var lf = require('../'); | ||
var through = require('through'); | ||
@@ -5,0 +4,0 @@ test('positive index trailing', function (t) { |
var test = require('tap').test; | ||
var sliceFile = require('../'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var fs = require('fs'); | ||
@@ -15,4 +15,5 @@ var wordFile = __dirname + '/data/words'; | ||
xs.slice(0,5).pipe(through( | ||
function (line) { | ||
function (line, _, next) { | ||
first.push(line.toString('utf8')); | ||
next(); | ||
}, | ||
@@ -29,4 +30,5 @@ function () { | ||
xs.sliceReverse(-10, -5).pipe(through( | ||
function (line) { | ||
function (line, _, next) { | ||
second.push(line.toString('utf8')); | ||
next(); | ||
}, | ||
@@ -33,0 +35,0 @@ function () { |
var test = require('tap').test; | ||
var sliceFile = require('../'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var fs = require('fs'); | ||
@@ -15,4 +15,5 @@ var wordFile = __dirname + '/data/words'; | ||
xs.sliceReverse(-5).pipe(through( | ||
function (line) { | ||
function (line, _, next) { | ||
first.push(line.toString('utf8')); | ||
next(); | ||
}, | ||
@@ -29,4 +30,5 @@ function () { | ||
xs.sliceReverse(-10, -5).pipe(through( | ||
function (line) { | ||
function (line, _, next) { | ||
second.push(line.toString('utf8')); | ||
next(); | ||
}, | ||
@@ -33,0 +35,0 @@ function () { |
var test = require('tap').test; | ||
var sliceFile = require('../'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
var fs = require('fs'); | ||
@@ -15,4 +15,5 @@ var wordFile = __dirname + '/data/words'; | ||
xs.slice(-5).pipe(through( | ||
function (line) { | ||
function (line, _, next) { | ||
first.push(line.toString('utf8')); | ||
next(); | ||
}, | ||
@@ -29,4 +30,5 @@ function () { | ||
xs.slice(-10, -5).pipe(through( | ||
function (line) { | ||
function (line, _, next) { | ||
second.push(line.toString('utf8')); | ||
next(); | ||
}, | ||
@@ -33,0 +35,0 @@ function () { |
var test = require('tap').test; | ||
var sf = require('../'); | ||
var through = require('through'); | ||
var fs = require('fs'); | ||
@@ -5,0 +4,0 @@ |
var test = require('tap').test; | ||
var sf = require('../'); | ||
var fs = require('fs'); | ||
var through = require('through'); | ||
var through = require('through2'); | ||
@@ -22,4 +22,5 @@ var file = __dirname + '/data/write.txt'; | ||
function write (line) { | ||
lines.push(line); | ||
function write (line, _, next) { | ||
lines.push(line.toString()); | ||
next(); | ||
} | ||
@@ -26,0 +27,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
975534
996
1
+ Addedsplit2@^0.2.1
+ Addedthrough2@^0.6.5
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedsplit2@0.2.1(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedthrough2@0.6.5(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedsplit@~0.2.1
- Removedthrough@~2.2.7
- Removedsplit@0.2.10(transitive)
- Removedthrough@2.2.7(transitive)