unzip.tests.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. var fs = require("fs");
  2. var assert = require("assert");
  3. var path = require("path");
  4. var test = require("./test")(module);
  5. var unzip = require("../lib/unzip");
  6. var promises = require("../lib/promises");
  7. test("unzip fails if given empty object", function() {
  8. return unzip.openZip({}).then(function() {
  9. assert.ok(false, "Expected failure");
  10. }, function(error) {
  11. assert.equal("Could not find file in options", error.message);
  12. });
  13. });
  14. test("unzip can open local zip file", function() {
  15. var zipPath = path.join(__dirname, "test-data/hello.zip");
  16. return unzip.openZip({path: zipPath}).then(function(zipFile) {
  17. return zipFile.read("hello", "utf8");
  18. }).then(function(contents) {
  19. assert.equal(contents, "Hello world\n");
  20. });
  21. });
  22. test('unzip can open Buffer', function() {
  23. var zipPath = path.join(__dirname, "test-data/hello.zip");
  24. return promises.nfcall(fs.readFile, zipPath)
  25. .then(function(buffer) {
  26. return unzip.openZip({buffer: buffer});
  27. })
  28. .then(function(zipFile) {
  29. return zipFile.read("hello", "utf8");
  30. })
  31. .then(function(contents) {
  32. assert.equal(contents, "Hello world\n");
  33. });
  34. });