fileSizeUnknownFlag.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 archive w/ file size unknown flag set (created by OS X Finder)", function (t) {
  9. var archive = path.join(__dirname, '../testData/compressed-OSX-Finder/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 archive w/ file size unknown flag set (created by OS X Finder)", function (t) {
  18. var archive = path.join(__dirname, '../testData/compressed-OSX-Finder/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-OSX-Finder/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. });
  42. test("archive w/ language encoding flag set", function (t) {
  43. var archive = path.join(__dirname, '../testData/compressed-flags-set/archive.zip');
  44. temp.mkdir('node-unzip-', function (err, dirPath) {
  45. if (err) {
  46. throw err;
  47. }
  48. var unzipExtractor = unzip.Extract({ path: dirPath });
  49. unzipExtractor.on('error', function(err) {
  50. throw err;
  51. });
  52. unzipExtractor.on('close', testExtractionResults);
  53. fs.createReadStream(archive).pipe(unzipExtractor);
  54. function testExtractionResults() {
  55. dirdiff(path.join(__dirname, '../testData/compressed-flags-set/inflated'), dirPath, {
  56. fileContents: true
  57. }, function (err, diffs) {
  58. if (err) {
  59. throw err;
  60. }
  61. t.equal(diffs.length, 0, 'extracted directory contents');
  62. t.end();
  63. });
  64. }
  65. });
  66. });