s3-zip 3.1.2 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: node_js
2
2
  node_js:
3
+ - 14
3
4
  - 12
4
5
  - 10
5
- - 8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "s3-zip",
3
- "version": "3.1.2",
3
+ "version": "3.2.1",
4
4
  "description": "Download selected files from an Amazon S3 bucket as a zip file.",
5
5
  "main": "s3-zip.js",
6
6
  "scripts": {
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "homepage": "https://github.com/orangewise/s3-zip#readme",
27
27
  "dependencies": {
28
- "archiver": "^3.1.1",
29
- "s3-files": "^2.0.0"
28
+ "archiver": "^5.2.0",
29
+ "s3-files": "^2.0.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "archiver-zip-encryptable": "^1.0.5",
package/s3-zip.js CHANGED
@@ -56,6 +56,7 @@ s3Zip.archiveStream = function (stream, filesS3, filesZip) {
56
56
  // Place files_s3[i] into the archive as files_zip[i]
57
57
  const i = filesS3.indexOf(file.path.startsWith(folder) ? file.path.substr(folder.length) : file.path)
58
58
  fname = (i >= 0 && i < filesZip.length) ? filesZip[i] : file.path
59
+ filesS3[i] = ''
59
60
  } else {
60
61
  // Just use the S3 file name
61
62
  fname = file.path
@@ -0,0 +1,82 @@
1
+ // Test s3-zip BUT using alternate file names for the same file which is listed multiple times
2
+
3
+ var s3Zip = require('../s3-zip.js')
4
+ var t = require('tap')
5
+ var fs = require('fs')
6
+ var Stream = require('stream')
7
+ var concat = require('concat-stream')
8
+ var join = require('path').join
9
+ var streamify = require('stream-array')
10
+ var tar = require('tar')
11
+
12
+ var fileStreamForFiles = function (files, preserveFolderPath) {
13
+ var rs = new Stream()
14
+ rs.readable = true
15
+
16
+ var fileCounter = 0
17
+ streamify(files).on('data', function (file) {
18
+ fileCounter += 1
19
+
20
+ var fileStream = fs.createReadStream(join(__dirname, file))
21
+ fileStream.pipe(
22
+ concat(function buffersEmit (buffer) {
23
+ // console.log('buffers concatenated, emit data for ', file);
24
+ var path = preserveFolderPath ? file : file.replace(/^.*[\\/]/, '')
25
+ rs.emit('data', { data: buffer, path: path })
26
+ })
27
+ )
28
+ fileStream.on('end', function () {
29
+ fileCounter -= 1
30
+ if (fileCounter < 1) {
31
+ // console.log('all files processed, emit end');
32
+ rs.emit('end')
33
+ }
34
+ })
35
+ })
36
+ return rs
37
+ }
38
+
39
+ var inputFiles = [
40
+ '/fixtures/folder/a/file.txt',
41
+ '/fixtures/folder/a/file.txt'
42
+ ]
43
+ var outputFiles = [
44
+ 'FILE_1_ALT_1.TXT',
45
+ 'FILE_1_ALT_2.TXT'
46
+ ]
47
+ var filesRead = []
48
+
49
+ t.test('test a tar archive with alternate names for one file listed many times', function (child) {
50
+ var outputPath = join(__dirname, '/test-same_file_alt_name.tar')
51
+ var output = fs.createWriteStream(outputPath)
52
+ var archive = s3Zip
53
+ .setFormat('tar')
54
+ .archiveStream(fileStreamForFiles(inputFiles, true), inputFiles, outputFiles)
55
+ .pipe(output)
56
+
57
+ archive.on('close', function () {
58
+ fs.createReadStream(outputPath)
59
+ .pipe(tar.list())
60
+ .on('entry', function (entry) {
61
+ filesRead.push(entry.path)
62
+ })
63
+ .on('end', function () {
64
+ child.same(filesRead, outputFiles)
65
+ child.end()
66
+ })
67
+ })
68
+ })
69
+
70
+ t.test('test archive with alternate names for one file listed many times', function (child) {
71
+ var archive = s3Zip
72
+ .archive({ region: 'region', bucket: 'bucket' },
73
+ '',
74
+ inputFiles,
75
+ outputFiles.map(file => {
76
+ return { name: file }
77
+ })
78
+ )
79
+
80
+ child.type(archive, 'object')
81
+ child.end()
82
+ })