@alienkarma/archiver 7.0.1-fork.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/LICENSE +22 -0
- package/README.md +89 -0
- package/index.js +39 -0
- package/lib/core.js +851 -0
- package/lib/error.js +37 -0
- package/lib/plugins/json.js +79 -0
- package/lib/plugins/tar.js +118 -0
- package/lib/plugins/zip.js +72 -0
- package/lib/utils.js +66 -0
- package/package.json +65 -0
package/lib/error.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import util from "util";
|
|
2
|
+
|
|
3
|
+
const ERROR_CODES = {
|
|
4
|
+
ABORTED: "archive was aborted",
|
|
5
|
+
DIRECTORYDIRPATHREQUIRED:
|
|
6
|
+
"diretory dirpath argument must be a non-empty string value",
|
|
7
|
+
DIRECTORYFUNCTIONINVALIDDATA:
|
|
8
|
+
"invalid data returned by directory custom data function",
|
|
9
|
+
ENTRYNAMEREQUIRED: "entry name must be a non-empty string value",
|
|
10
|
+
FILEFILEPATHREQUIRED:
|
|
11
|
+
"file filepath argument must be a non-empty string value",
|
|
12
|
+
FINALIZING: "archive already finalizing",
|
|
13
|
+
QUEUECLOSED: "queue closed",
|
|
14
|
+
NOENDMETHOD: "no suitable finalize/end method defined by module",
|
|
15
|
+
DIRECTORYNOTSUPPORTED: "support for directory entries not defined by module",
|
|
16
|
+
FORMATSET: "archive format already set",
|
|
17
|
+
INPUTSTEAMBUFFERREQUIRED:
|
|
18
|
+
"input source must be valid Stream or Buffer instance",
|
|
19
|
+
MODULESET: "module already set",
|
|
20
|
+
SYMLINKNOTSUPPORTED: "support for symlink entries not defined by module",
|
|
21
|
+
SYMLINKFILEPATHREQUIRED:
|
|
22
|
+
"symlink filepath argument must be a non-empty string value",
|
|
23
|
+
SYMLINKTARGETREQUIRED:
|
|
24
|
+
"symlink target argument must be a non-empty string value",
|
|
25
|
+
ENTRYNOTSUPPORTED: "entry not supported",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function ArchiverError(code, data) {
|
|
29
|
+
Error.captureStackTrace(this, this.constructor);
|
|
30
|
+
//this.name = this.constructor.name;
|
|
31
|
+
this.message = ERROR_CODES[code] || code;
|
|
32
|
+
this.code = code;
|
|
33
|
+
this.data = data;
|
|
34
|
+
}
|
|
35
|
+
util.inherits(ArchiverError, Error);
|
|
36
|
+
|
|
37
|
+
export { ArchiverError };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Transform } from "readable-stream";
|
|
2
|
+
import crc32 from "buffer-crc32";
|
|
3
|
+
import { collectStream } from "../utils.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* JSON Format Plugin
|
|
7
|
+
*
|
|
8
|
+
* @module plugins/json
|
|
9
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
|
|
10
|
+
* @copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
11
|
+
*/
|
|
12
|
+
export default class Json extends Transform {
|
|
13
|
+
/**
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {(JsonOptions|TransformOptions)} options
|
|
16
|
+
*/
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super({ ...options });
|
|
19
|
+
this.files = [];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* [_transform description]
|
|
23
|
+
*
|
|
24
|
+
* @private
|
|
25
|
+
* @param {Buffer} chunk
|
|
26
|
+
* @param {String} encoding
|
|
27
|
+
* @param {Function} callback
|
|
28
|
+
* @return void
|
|
29
|
+
*/
|
|
30
|
+
_transform(chunk, encoding, callback) {
|
|
31
|
+
callback(null, chunk);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* [_writeStringified description]
|
|
35
|
+
*
|
|
36
|
+
* @private
|
|
37
|
+
* @return void
|
|
38
|
+
*/
|
|
39
|
+
_writeStringified() {
|
|
40
|
+
var fileString = JSON.stringify(this.files);
|
|
41
|
+
this.write(fileString);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* [append description]
|
|
45
|
+
*
|
|
46
|
+
* @param {(Buffer|Stream)} source
|
|
47
|
+
* @param {EntryData} data
|
|
48
|
+
* @param {Function} callback
|
|
49
|
+
* @return void
|
|
50
|
+
*/
|
|
51
|
+
append(source, data, callback) {
|
|
52
|
+
var self = this;
|
|
53
|
+
data.crc32 = 0;
|
|
54
|
+
function onend(err, sourceBuffer) {
|
|
55
|
+
if (err) {
|
|
56
|
+
callback(err);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
data.size = sourceBuffer.length || 0;
|
|
60
|
+
data.crc32 = crc32.unsigned(sourceBuffer);
|
|
61
|
+
self.files.push(data);
|
|
62
|
+
callback(null, data);
|
|
63
|
+
}
|
|
64
|
+
if (data.sourceType === "buffer") {
|
|
65
|
+
onend(null, source);
|
|
66
|
+
} else if (data.sourceType === "stream") {
|
|
67
|
+
collectStream(source, onend);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* [finalize description]
|
|
72
|
+
*
|
|
73
|
+
* @return void
|
|
74
|
+
*/
|
|
75
|
+
finalize() {
|
|
76
|
+
this._writeStringified();
|
|
77
|
+
this.end();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import zlib from "zlib";
|
|
2
|
+
import engine from "tar-stream";
|
|
3
|
+
import { collectStream } from "../utils.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TAR Format Plugin
|
|
7
|
+
*
|
|
8
|
+
* @module plugins/tar
|
|
9
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
|
|
10
|
+
* @copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
11
|
+
*/
|
|
12
|
+
export default class Tar {
|
|
13
|
+
/**
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {TarOptions} options
|
|
16
|
+
*/
|
|
17
|
+
constructor(options) {
|
|
18
|
+
options = this.options = {
|
|
19
|
+
gzip: false,
|
|
20
|
+
...options,
|
|
21
|
+
};
|
|
22
|
+
if (typeof options.gzipOptions !== "object") {
|
|
23
|
+
options.gzipOptions = {};
|
|
24
|
+
}
|
|
25
|
+
this.engine = engine.pack(options);
|
|
26
|
+
this.compressor = false;
|
|
27
|
+
if (options.gzip) {
|
|
28
|
+
this.compressor = zlib.createGzip(options.gzipOptions);
|
|
29
|
+
this.compressor.on("error", this._onCompressorError.bind(this));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* [_onCompressorError description]
|
|
34
|
+
*
|
|
35
|
+
* @private
|
|
36
|
+
* @param {Error} err
|
|
37
|
+
* @return void
|
|
38
|
+
*/
|
|
39
|
+
_onCompressorError(err) {
|
|
40
|
+
this.engine.emit("error", err);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* [append description]
|
|
44
|
+
*
|
|
45
|
+
* @param {(Buffer|Stream)} source
|
|
46
|
+
* @param {TarEntryData} data
|
|
47
|
+
* @param {Function} callback
|
|
48
|
+
* @return void
|
|
49
|
+
*/
|
|
50
|
+
append(source, data, callback) {
|
|
51
|
+
var self = this;
|
|
52
|
+
data.mtime = data.date;
|
|
53
|
+
function append(err, sourceBuffer) {
|
|
54
|
+
if (err) {
|
|
55
|
+
callback(err);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
self.engine.entry(data, sourceBuffer, function (err) {
|
|
59
|
+
callback(err, data);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (data.sourceType === "buffer") {
|
|
63
|
+
append(null, source);
|
|
64
|
+
} else if (data.sourceType === "stream" && data.stats) {
|
|
65
|
+
data.size = data.stats.size;
|
|
66
|
+
var entry = self.engine.entry(data, function (err) {
|
|
67
|
+
callback(err, data);
|
|
68
|
+
});
|
|
69
|
+
source.pipe(entry);
|
|
70
|
+
} else if (data.sourceType === "stream") {
|
|
71
|
+
collectStream(source, append);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* [finalize description]
|
|
76
|
+
*
|
|
77
|
+
* @return void
|
|
78
|
+
*/
|
|
79
|
+
finalize() {
|
|
80
|
+
this.engine.finalize();
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* [on description]
|
|
84
|
+
*
|
|
85
|
+
* @return this.engine
|
|
86
|
+
*/
|
|
87
|
+
on() {
|
|
88
|
+
return this.engine.on.apply(this.engine, arguments);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* [pipe description]
|
|
92
|
+
*
|
|
93
|
+
* @param {String} destination
|
|
94
|
+
* @param {Object} options
|
|
95
|
+
* @return this.engine
|
|
96
|
+
*/
|
|
97
|
+
pipe(destination, options) {
|
|
98
|
+
if (this.compressor) {
|
|
99
|
+
return this.engine.pipe
|
|
100
|
+
.apply(this.engine, [this.compressor])
|
|
101
|
+
.pipe(destination, options);
|
|
102
|
+
} else {
|
|
103
|
+
return this.engine.pipe.apply(this.engine, arguments);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* [unpipe description]
|
|
108
|
+
*
|
|
109
|
+
* @return this.engine
|
|
110
|
+
*/
|
|
111
|
+
unpipe() {
|
|
112
|
+
if (this.compressor) {
|
|
113
|
+
return this.compressor.unpipe.apply(this.compressor, arguments);
|
|
114
|
+
} else {
|
|
115
|
+
return this.engine.unpipe.apply(this.engine, arguments);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import engine from "zip-stream";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ZIP Format Plugin
|
|
5
|
+
*
|
|
6
|
+
* @module plugins/zip
|
|
7
|
+
* @license [MIT]{@link https://github.com/archiverjs/node-archiver/blob/master/LICENSE}
|
|
8
|
+
* @copyright (c) 2012-2014 Chris Talkington, contributors.
|
|
9
|
+
*/
|
|
10
|
+
export default class Zip {
|
|
11
|
+
/**
|
|
12
|
+
* @constructor
|
|
13
|
+
* @param {ZipOptions} [options]
|
|
14
|
+
* @param {String} [options.comment] Sets the zip archive comment.
|
|
15
|
+
* @param {Boolean} [options.forceLocalTime=false] Forces the archive to contain local file times instead of UTC.
|
|
16
|
+
* @param {Boolean} [options.forceZip64=false] Forces the archive to contain ZIP64 headers.
|
|
17
|
+
* @param {Boolean} [options.namePrependSlash=false] Prepends a forward slash to archive file paths.
|
|
18
|
+
* @param {Boolean} [options.store=false] Sets the compression method to STORE.
|
|
19
|
+
* @param {Object} [options.zlib] Passed to [zlib]{@link https://nodejs.org/api/zlib.html#zlib_class_options}
|
|
20
|
+
*/
|
|
21
|
+
constructor(options) {
|
|
22
|
+
options = this.options = {
|
|
23
|
+
comment: "",
|
|
24
|
+
forceUTC: false,
|
|
25
|
+
namePrependSlash: false,
|
|
26
|
+
store: false,
|
|
27
|
+
...options,
|
|
28
|
+
};
|
|
29
|
+
this.engine = new engine(options);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @param {(Buffer|Stream)} source
|
|
33
|
+
* @param {ZipEntryData} data
|
|
34
|
+
* @param {String} data.name Sets the entry name including internal path.
|
|
35
|
+
* @param {(String|Date)} [data.date=NOW()] Sets the entry date.
|
|
36
|
+
* @param {Number} [data.mode=D:0755/F:0644] Sets the entry permissions.
|
|
37
|
+
* @param {String} [data.prefix] Sets a path prefix for the entry name. Useful
|
|
38
|
+
* when working with methods like `directory` or `glob`.
|
|
39
|
+
* @param {fs.Stats} [data.stats] Sets the fs stat data for this entry allowing
|
|
40
|
+
* for reduction of fs stat calls when stat data is already known.
|
|
41
|
+
* @param {Boolean} [data.store=ZipOptions.store] Sets the compression method to STORE.
|
|
42
|
+
* @param {Function} callback
|
|
43
|
+
* @return void
|
|
44
|
+
*/
|
|
45
|
+
append(source, data, callback) {
|
|
46
|
+
this.engine.entry(source, data, callback);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @return void
|
|
50
|
+
*/
|
|
51
|
+
finalize() {
|
|
52
|
+
this.engine.finalize();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @return this.engine
|
|
56
|
+
*/
|
|
57
|
+
on() {
|
|
58
|
+
return this.engine.on.apply(this.engine, arguments);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @return this.engine
|
|
62
|
+
*/
|
|
63
|
+
pipe() {
|
|
64
|
+
return this.engine.pipe.apply(this.engine, arguments);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @return this.engine
|
|
68
|
+
*/
|
|
69
|
+
unpipe() {
|
|
70
|
+
return this.engine.unpipe.apply(this.engine, arguments);
|
|
71
|
+
}
|
|
72
|
+
}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import normalizePath from "normalize-path";
|
|
2
|
+
import { PassThrough } from "readable-stream";
|
|
3
|
+
import { isStream } from "is-stream";
|
|
4
|
+
|
|
5
|
+
export function collectStream(source, callback) {
|
|
6
|
+
var collection = [];
|
|
7
|
+
var size = 0;
|
|
8
|
+
|
|
9
|
+
source.on("error", callback);
|
|
10
|
+
|
|
11
|
+
source.on("data", function (chunk) {
|
|
12
|
+
collection.push(chunk);
|
|
13
|
+
size += chunk.length;
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
source.on("end", function () {
|
|
17
|
+
var buf = Buffer.alloc(size);
|
|
18
|
+
var offset = 0;
|
|
19
|
+
|
|
20
|
+
collection.forEach(function (data) {
|
|
21
|
+
data.copy(buf, offset);
|
|
22
|
+
offset += data.length;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
callback(null, buf);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function dateify(dateish) {
|
|
30
|
+
dateish = dateish || new Date();
|
|
31
|
+
|
|
32
|
+
if (dateish instanceof Date) {
|
|
33
|
+
dateish = dateish;
|
|
34
|
+
} else if (typeof dateish === "string") {
|
|
35
|
+
dateish = new Date(dateish);
|
|
36
|
+
} else {
|
|
37
|
+
dateish = new Date();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return dateish;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function normalizeInputSource(source) {
|
|
44
|
+
if (source === null) {
|
|
45
|
+
return Buffer.alloc(0);
|
|
46
|
+
} else if (typeof source === "string") {
|
|
47
|
+
return Buffer.from(source);
|
|
48
|
+
} else if (isStream(source)) {
|
|
49
|
+
// Always pipe through a PassThrough stream to guarantee pausing the stream if it's already flowing,
|
|
50
|
+
// since it will only be processed in a (distant) future iteration of the event loop, and will lose
|
|
51
|
+
// data if already flowing now.
|
|
52
|
+
return source.pipe(new PassThrough());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return source;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function sanitizePath(filepath) {
|
|
59
|
+
return normalizePath(filepath, false)
|
|
60
|
+
.replace(/^\w+:/, "")
|
|
61
|
+
.replace(/^(\.\.\/|\/)+/, "");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function trailingSlashIt(str) {
|
|
65
|
+
return str.slice(-1) !== "/" ? str + "/" : str;
|
|
66
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alienkarma/archiver",
|
|
3
|
+
"version": "7.0.1-fork.1",
|
|
4
|
+
"description": "a streaming interface for archive generation",
|
|
5
|
+
"homepage": "https://github.com/archiverjs/node-archiver",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Chris Talkington",
|
|
8
|
+
"url": "http://christalkington.com/"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/archiverjs/node-archiver.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/archiverjs/node-archiver/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": "./index.js",
|
|
20
|
+
"files": [
|
|
21
|
+
"index.js",
|
|
22
|
+
"lib"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "mocha --reporter dot",
|
|
29
|
+
"bench": "node benchmark/simple/pack-zip.js"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"async": "^3.2.4",
|
|
33
|
+
"buffer-crc32": "^1.0.0",
|
|
34
|
+
"is-stream": "^4.0.0",
|
|
35
|
+
"lazystream": "^1.0.0",
|
|
36
|
+
"minimatch": "^10.2.1",
|
|
37
|
+
"normalize-path": "^3.0.0",
|
|
38
|
+
"readable-stream": "^4.0.0",
|
|
39
|
+
"readdir-glob": "^1.1.3",
|
|
40
|
+
"tar-stream": "^3.0.0",
|
|
41
|
+
"zip-stream": "^7.0.2"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"archiver-jsdoc-theme": "1.1.3",
|
|
45
|
+
"chai": "4.5.0",
|
|
46
|
+
"jsdoc": "4.0.4",
|
|
47
|
+
"mkdirp": "3.0.1",
|
|
48
|
+
"mocha": "10.8.2",
|
|
49
|
+
"prettier": "3.5.3",
|
|
50
|
+
"rimraf": "5.0.10",
|
|
51
|
+
"stream-bench": "0.1.2",
|
|
52
|
+
"tar": "6.2.1",
|
|
53
|
+
"yauzl": "3.2.0"
|
|
54
|
+
},
|
|
55
|
+
"keywords": [
|
|
56
|
+
"archive",
|
|
57
|
+
"archiver",
|
|
58
|
+
"stream",
|
|
59
|
+
"zip",
|
|
60
|
+
"tar"
|
|
61
|
+
],
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"registry": "https://registry.npmjs.org/"
|
|
64
|
+
}
|
|
65
|
+
}
|