thedesk/app/node_modules/unzip/test/pipeSingleEntry.js

29 lines
948 B
JavaScript
Raw Normal View History

2018-02-18 18:29:06 +11:00
'use strict';
var test = require('tap').test;
var fs = require('fs');
var path = require('path');
var temp = require('temp');
var streamBuffers = require("stream-buffers");
var unzip = require('../');
test("pipe a single file entry out of a zip", function (t) {
var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip');
fs.createReadStream(archive)
.pipe(unzip.Parse())
.on('entry', function(entry) {
if (entry.path === 'file.txt') {
var writableStream = new streamBuffers.WritableStreamBuffer();
writableStream.on('close', function () {
var str = writableStream.getContentsAsString('utf8');
var fileStr = fs.readFileSync(path.join(__dirname, '../testData/compressed-standard/inflated/file.txt'), 'utf8')
t.equal(str, fileStr);
t.end();
});
entry.pipe(writableStream);
} else {
entry.autodrain();
}
});
});