forked from orangewise/s3-zip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_s3_zip_alt_names.js
78 lines (72 loc) · 2.16 KB
/
test_s3_zip_alt_names.js
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
// Test s3-zip BUT using alternate file names in the resulting zip archive
var s3Zip = require('../s3-zip.js')
var t = require('tap')
var fs = require('fs')
var Stream = require('stream')
var concat = require('concat-stream')
var yauzl = require('yauzl')
var join = require('path').join
var fileStream = function (file, forceError) {
var rs = new Stream()
rs.readable = true
var fileStream = fs.createReadStream(join(__dirname, file))
fileStream
.pipe(concat(
function buffersEmit (buffer) {
if (forceError) {
console.log('send end to finalize archive')
rs.emit('end')
} else {
rs.emit('data', { data: buffer, path: file })
}
})
)
fileStream
.on('end', function () {
console.log('end fileStream')
rs.emit('end')
})
return rs
}
var file1 = '/fixtures/file.txt'
var file1Alt = 'FILE_ALT.TXT'
// Stub: var fileStream = s3Files.createFileStream(keyStream);
var sinon = require('sinon')
var proxyquire = require('proxyquire')
var s3Stub = fileStream(file1)
s3Zip = proxyquire('../s3-zip.js', {
's3-files': { 'createFileStream': sinon.stub().returns(s3Stub) }
})
t.test('test archiveStream and zip file with alternate file name in zip archive', function (child) {
var output = fs.createWriteStream(join(__dirname, '/test_alt.zip'))
var s = fileStream(file1)
var archive = s3Zip
.archiveStream(s, [file1], [file1Alt])
.pipe(output)
archive.on('close', function () {
console.log('+++++++++++')
yauzl.open(join(__dirname, '/test_alt.zip'), function (err, zip) {
if (err) console.log('err', err)
zip.on('entry', function (entry) {
// console.log(entry);
child.same(entry.fileName, file1Alt)
child.same(entry.compressedSize, 11)
child.same(entry.uncompressedSize, 20)
})
zip.on('close', function () {
child.end()
})
})
})
child.type(archive, 'object')
})
t.test('test archive with alternate zip archive names', function (child) {
var archive = s3Zip
.archive({ region: 'region', bucket: 'bucket' },
'folder',
[file1],
[file1Alt]
)
child.type(archive, 'object')
child.end()
})