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