parse-discard.js 643 B

1234567891011121314151617181920212223242526272829
  1. var tap = require("tap")
  2. , tar = require("../tar.js")
  3. , fs = require("fs")
  4. , path = require("path")
  5. , file = path.resolve(__dirname, "fixtures/c.tar")
  6. tap.test("parser test", function (t) {
  7. var parser = tar.Parse()
  8. var total = 0
  9. var dataTotal = 0
  10. parser.on("end", function () {
  11. t.equals(total-513,dataTotal,'should have discarded only c.txt')
  12. t.end()
  13. })
  14. fs.createReadStream(file)
  15. .pipe(parser)
  16. .on('entry',function(entry){
  17. if(entry.path === 'c.txt') entry.abort()
  18. total += entry.size;
  19. entry.on('data',function(data){
  20. dataTotal += data.length
  21. })
  22. })
  23. })