forked from archiverjs/node-compress-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip-archive-output-stream.js
More file actions
127 lines (99 loc) · 3.67 KB
/
Copy pathzip-archive-output-stream.js
File metadata and controls
127 lines (99 loc) · 3.67 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*global before,describe,it */
var fs = require('fs');
var stream = require('stream');
var assert = require('chai').assert;
var mkdir = require('mkdirp');
var helpers = require('./helpers');
var WriteHashStream = helpers.WriteHashStream;
var testBuffer = helpers.binaryBuffer(1024 * 16);
var testDate = new Date('Jan 03 2013 14:26:38 GMT');
var commons = require('../lib/compress-commons');
var ZipArchiveEntry = commons.ZipArchiveEntry;
var ZipArchiveOutputStream = commons.ZipArchiveOutputStream;
describe('ZipArchiveOutputStream', function() {
before(function() {
mkdir.sync('tmp');
});
describe('#entry', function() {
it('should append Buffer sources', function(done) {
var archive = new ZipArchiveOutputStream();
var testStream = new WriteHashStream('tmp/zip-buffer.zip');
var entry = new ZipArchiveEntry('buffer.txt');
testStream.on('close', function() {
done();
});
archive.pipe(testStream);
archive.entry(entry, testBuffer).finish();
});
it('should append Stream sources', function(done) {
var archive = new ZipArchiveOutputStream();
var testStream = new WriteHashStream('tmp/zip-stream.zip');
var entry = new ZipArchiveEntry('stream.txt');
testStream.on('close', function() {
done();
});
archive.pipe(testStream);
archive.entry(entry, fs.createReadStream('test/fixtures/test.txt')).finish();
});
it('should stop streaming on Stream error', function(done) {
var archive = new ZipArchiveOutputStream();
var testStream = new WriteHashStream('tmp/zip-stream.zip');
var entry = new ZipArchiveEntry('stream.txt');
var callbackError = null;
var callbackCalls = 0;
testStream.on('close', function() {
assert.equal(callbackError.message, 'something went wrong');
assert.equal(callbackCalls, 1);
done();
});
archive.pipe(testStream);
var file = new stream.Transform();
archive.entry(entry, file, function(err) {
callbackCalls += 1;
callbackError = err;
});
archive.finish();
process.nextTick(function() {
file.emit('error', new Error('something went wrong'));
})
});
it('should append multiple sources', function(done) {
var archive = new ZipArchiveOutputStream();
var testStream = new WriteHashStream('tmp/zip-multiple.zip');
var entry = new ZipArchiveEntry('string.txt');
var entry2 = new ZipArchiveEntry('buffer.txt');
var entry3 = new ZipArchiveEntry('stream.txt');
var entry4 = new ZipArchiveEntry('stream-store.png');
entry4.setMethod(0);
testStream.on('close', function() {
done();
});
archive.pipe(testStream);
archive.entry(entry, 'string', function(err) {
if (err) throw err;
archive.entry(entry2, testBuffer, function(err) {
if (err) throw err;
archive.entry(entry3, fs.createReadStream('test/fixtures/test.txt'), function(err) {
if (err) throw err;
archive.entry(entry4, fs.createReadStream('test/fixtures/image.png'), function(err) {
if (err) throw err;
archive.finish();
});
});
});
});
});
it('should force ZIP64', function(done) {
var archive = new ZipArchiveOutputStream({
forceZip64: true
});
var testStream = new WriteHashStream('tmp/zip-stream64.zip');
var entry = new ZipArchiveEntry('stream.txt');
testStream.on('close', function() {
done();
});
archive.pipe(testStream);
archive.entry(entry, fs.createReadStream('test/fixtures/test.txt')).finish();
});
});
});