compressed.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. var test = require('tap').test;
  3. var fs = require('fs');
  4. var path = require('path');
  5. var temp = require('temp');
  6. var dirdiff = require('dirdiff');
  7. var unzip = require('../');
  8. test("parse compressed archive (created by POSIX zip)", function (t) {
  9. var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip');
  10. var unzipParser = unzip.Parse();
  11. fs.createReadStream(archive).pipe(unzipParser);
  12. unzipParser.on('error', function(err) {
  13. throw err;
  14. });
  15. unzipParser.on('close', t.end.bind(this));
  16. });
  17. test("extract compressed archive w/ file sizes known prior to zlib inflation (created by POSIX zip)", function (t) {
  18. var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip');
  19. temp.mkdir('node-unzip-', function (err, dirPath) {
  20. if (err) {
  21. throw err;
  22. }
  23. var unzipExtractor = unzip.Extract({ path: dirPath });
  24. unzipExtractor.on('error', function(err) {
  25. throw err;
  26. });
  27. unzipExtractor.on('close', testExtractionResults);
  28. fs.createReadStream(archive).pipe(unzipExtractor);
  29. function testExtractionResults() {
  30. dirdiff(path.join(__dirname, '../testData/compressed-standard/inflated'), dirPath, {
  31. fileContents: true
  32. }, function (err, diffs) {
  33. if (err) {
  34. throw err;
  35. }
  36. t.equal(diffs.length, 0, 'extracted directory contents');
  37. t.end();
  38. });
  39. }
  40. });
  41. });