Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding entity.discard() to stop data events
entity.discard() is a performance optimization for those using this library to only read specific files from the tar. the parser looks at this property in the same manner it looks at _remaining to know when to skip calling write on the entity. an entity which discard() has been called on will not emit any more data events. discard() does not take any arguments and only sets the value of _discard to true. this saves 100ms or so for me just `stating` all of the files in the npm v 3 tar
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var tap = require("tap") | ||
, tar = require("../tar.js") | ||
, fs = require("fs") | ||
, path = require("path") | ||
, file = path.resolve(__dirname, "fixtures/c.tar") | ||
|
||
tap.test("parser test", function (t) { | ||
var parser = tar.Parse() | ||
var total = 0; | ||
var dataTotal = 0; | ||
|
||
parser.on("end", function () { | ||
|
||
t.equals(total-513,dataTotal,'should have discarded only c.txt') | ||
|
||
t.end() | ||
}) | ||
|
||
fs.createReadStream(file) | ||
.pipe(parser) | ||
.on('entry',function(entry){ | ||
if(entry.path === 'c.txt') entry.discard() | ||
|
||
total += entry.size; | ||
entry.on('data',function(data){ | ||
dataTotal += data.length | ||
}) | ||
}) | ||
}) |