archiver-node 8.0.3 → 8.0.5
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/cjs/Archiver.js +768 -679
- package/cjs/archivers/JsonArchive.js +35 -42
- package/cjs/archivers/TarArchive.js +35 -42
- package/cjs/archivers/ZipArchive.js +35 -42
- package/cjs/error.js +10 -38
- package/cjs/lazystream.js +97 -51
- package/cjs/plugins/json.js +106 -102
- package/cjs/plugins/tar.js +128 -131
- package/cjs/plugins/zip.js +90 -95
- package/cjs/utils.js +27 -55
- package/lib/Archiver.js +1 -6
- package/package.json +6 -4
- package/lib/readdir-glob.js +0 -216
package/cjs/Archiver.js
CHANGED
|
@@ -1,183 +1,181 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var Archiver_exports = {};
|
|
29
|
-
__export(Archiver_exports, {
|
|
30
|
-
default: () => Archiver
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
31
5
|
});
|
|
32
|
-
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _fs = require("fs");
|
|
8
|
+
var _isStream = require("is-stream");
|
|
9
|
+
var _readdirGlob = _interopRequireDefault(require("readdir-glob"));
|
|
10
|
+
var _lazystream = require("./lazystream.js");
|
|
11
|
+
var _async = require("async");
|
|
12
|
+
var _path = require("path");
|
|
13
|
+
var _error = require("./error.js");
|
|
14
|
+
var _readableStream = require("readable-stream");
|
|
15
|
+
var _utils = require("./utils.js");
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
17
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
18
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
21
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
22
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
24
|
+
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
25
|
+
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
26
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
27
|
+
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
28
|
+
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
29
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
30
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
31
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
32
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
33
|
+
var ReaddirGlob = _readdirGlob["default"].ReaddirGlob;
|
|
34
|
+
var win32 = process.platform === "win32";
|
|
35
|
+
var Archiver = exports["default"] = /*#__PURE__*/function (_Transform) {
|
|
36
|
+
/**
|
|
37
|
+
* @constructor
|
|
38
|
+
* @param {String} format The archive format to use.
|
|
39
|
+
* @param {(CoreOptions|TransformOptions)} options See also {@link ZipOptions} and {@link TarOptions}.
|
|
52
40
|
*/
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
function Archiver(options) {
|
|
42
|
+
var _this;
|
|
43
|
+
_classCallCheck(this, Archiver);
|
|
44
|
+
options = _objectSpread({
|
|
55
45
|
highWaterMark: 1024 * 1024,
|
|
56
|
-
statConcurrency: 4
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
this._statQueue.drain(this._onQueueDrain.bind(this));
|
|
76
|
-
this._state = {
|
|
46
|
+
statConcurrency: 4
|
|
47
|
+
}, options);
|
|
48
|
+
_this = _callSuper(this, Archiver, [options]);
|
|
49
|
+
_defineProperty(_this, "_supportsDirectory", false);
|
|
50
|
+
_defineProperty(_this, "_supportsSymlink", false);
|
|
51
|
+
_this.options = options;
|
|
52
|
+
_this._format = false;
|
|
53
|
+
_this._module = false;
|
|
54
|
+
_this._pending = 0;
|
|
55
|
+
_this._pointer = 0;
|
|
56
|
+
_this._entriesCount = 0;
|
|
57
|
+
_this._entriesProcessedCount = 0;
|
|
58
|
+
_this._fsEntriesTotalBytes = 0;
|
|
59
|
+
_this._fsEntriesProcessedBytes = 0;
|
|
60
|
+
_this._queue = (0, _async.queue)(_this._onQueueTask.bind(_this), 1);
|
|
61
|
+
_this._queue.drain(_this._onQueueDrain.bind(_this));
|
|
62
|
+
_this._statQueue = (0, _async.queue)(_this._onStatQueueTask.bind(_this), options.statConcurrency);
|
|
63
|
+
_this._statQueue.drain(_this._onQueueDrain.bind(_this));
|
|
64
|
+
_this._state = {
|
|
77
65
|
aborted: false,
|
|
78
66
|
finalize: false,
|
|
79
67
|
finalizing: false,
|
|
80
68
|
finalized: false,
|
|
81
69
|
modulePiped: false
|
|
82
70
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Internal logic for `abort`.
|
|
87
|
-
*
|
|
88
|
-
* @private
|
|
89
|
-
* @return void
|
|
90
|
-
*/
|
|
91
|
-
_abort() {
|
|
92
|
-
this._state.aborted = true;
|
|
93
|
-
this._queue.kill();
|
|
94
|
-
this._statQueue.kill();
|
|
95
|
-
if (this._queue.idle()) {
|
|
96
|
-
this._shutdown();
|
|
97
|
-
}
|
|
71
|
+
_this._streams = [];
|
|
72
|
+
return _this;
|
|
98
73
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @
|
|
104
|
-
* @
|
|
105
|
-
* @return void
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Internal logic for `abort`.
|
|
77
|
+
*
|
|
78
|
+
* @private
|
|
79
|
+
* @return void
|
|
106
80
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
81
|
+
_inherits(Archiver, _Transform);
|
|
82
|
+
return _createClass(Archiver, [{
|
|
83
|
+
key: "_abort",
|
|
84
|
+
value: function _abort() {
|
|
85
|
+
this._state.aborted = true;
|
|
86
|
+
this._queue.kill();
|
|
87
|
+
this._statQueue.kill();
|
|
88
|
+
if (this._queue.idle()) {
|
|
89
|
+
this._shutdown();
|
|
90
|
+
}
|
|
115
91
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Internal helper for appending files.
|
|
94
|
+
*
|
|
95
|
+
* @private
|
|
96
|
+
* @param {String} filepath The source filepath.
|
|
97
|
+
* @param {EntryData} data The entry data.
|
|
98
|
+
* @return void
|
|
99
|
+
*/
|
|
100
|
+
}, {
|
|
101
|
+
key: "_append",
|
|
102
|
+
value: function _append(filepath, data) {
|
|
103
|
+
data = data || {};
|
|
104
|
+
var task = {
|
|
105
|
+
source: null,
|
|
106
|
+
filepath: filepath
|
|
107
|
+
};
|
|
108
|
+
if (!data.name) {
|
|
109
|
+
data.name = filepath;
|
|
110
|
+
}
|
|
111
|
+
data.sourcePath = filepath;
|
|
112
|
+
task.data = data;
|
|
113
|
+
this._entriesCount++;
|
|
114
|
+
if (data.stats && data.stats instanceof _fs.Stats) {
|
|
115
|
+
task = this._updateQueueTaskWithStats(task, data.stats);
|
|
116
|
+
if (task) {
|
|
117
|
+
if (data.stats.size) {
|
|
118
|
+
this._fsEntriesTotalBytes += data.stats.size;
|
|
119
|
+
}
|
|
120
|
+
this._queue.push(task);
|
|
124
121
|
}
|
|
125
|
-
|
|
122
|
+
} else {
|
|
123
|
+
this._statQueue.push(task);
|
|
126
124
|
}
|
|
127
|
-
} else {
|
|
128
|
-
this._statQueue.push(task);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Internal logic for `finalize`.
|
|
133
|
-
*
|
|
134
|
-
* @private
|
|
135
|
-
* @return void
|
|
136
|
-
*/
|
|
137
|
-
_finalize() {
|
|
138
|
-
if (this._state.finalizing || this._state.finalized || this._state.aborted) {
|
|
139
|
-
return;
|
|
140
125
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Internal logic for `finalize`.
|
|
128
|
+
*
|
|
129
|
+
* @private
|
|
130
|
+
* @return void
|
|
131
|
+
*/
|
|
132
|
+
}, {
|
|
133
|
+
key: "_finalize",
|
|
134
|
+
value: function _finalize() {
|
|
135
|
+
if (this._state.finalizing || this._state.finalized || this._state.aborted) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this._state.finalizing = true;
|
|
139
|
+
this._moduleFinalize();
|
|
140
|
+
this._state.finalizing = false;
|
|
141
|
+
this._state.finalized = true;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Checks the various state variables to determine if we can `finalize`.
|
|
145
|
+
*
|
|
146
|
+
* @private
|
|
147
|
+
* @return {Boolean}
|
|
148
|
+
*/
|
|
149
|
+
}, {
|
|
150
|
+
key: "_maybeFinalize",
|
|
151
|
+
value: function _maybeFinalize() {
|
|
152
|
+
if (this._state.finalizing || this._state.finalized || this._state.aborted) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (this._state.finalize && this._pending === 0 && this._queue.idle() && this._statQueue.idle()) {
|
|
156
|
+
this._finalize();
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
154
159
|
return false;
|
|
155
160
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
callback();
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
this._module.append(
|
|
178
|
-
source,
|
|
179
|
-
data,
|
|
180
|
-
function(err) {
|
|
161
|
+
/**
|
|
162
|
+
* Appends an entry to the module.
|
|
163
|
+
*
|
|
164
|
+
* @private
|
|
165
|
+
* @fires Archiver#entry
|
|
166
|
+
* @param {(Buffer|Stream)} source
|
|
167
|
+
* @param {EntryData} data
|
|
168
|
+
* @param {Function} callback
|
|
169
|
+
* @return void
|
|
170
|
+
*/
|
|
171
|
+
}, {
|
|
172
|
+
key: "_moduleAppend",
|
|
173
|
+
value: function _moduleAppend(source, data, callback) {
|
|
174
|
+
if (this._state.aborted) {
|
|
175
|
+
callback();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this._module.append(source, data, function (err) {
|
|
181
179
|
this._task = null;
|
|
182
180
|
if (this._state.aborted) {
|
|
183
181
|
this._shutdown();
|
|
@@ -188,11 +186,21 @@ class Archiver extends import_readable_stream.Transform {
|
|
|
188
186
|
setImmediate(callback);
|
|
189
187
|
return;
|
|
190
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Fires when the entry's input has been processed and appended to the archive.
|
|
191
|
+
*
|
|
192
|
+
* @event Archiver#entry
|
|
193
|
+
* @type {EntryData}
|
|
194
|
+
*/
|
|
191
195
|
this.emit("entry", data);
|
|
192
196
|
this._entriesProcessedCount++;
|
|
193
197
|
if (data.stats && data.stats.size) {
|
|
194
198
|
this._fsEntriesProcessedBytes += data.stats.size;
|
|
195
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* @event Archiver#progress
|
|
202
|
+
* @type {ProgressData}
|
|
203
|
+
*/
|
|
196
204
|
this.emit("progress", {
|
|
197
205
|
entries: {
|
|
198
206
|
total: this._entriesCount,
|
|
@@ -204,175 +212,197 @@ class Archiver extends import_readable_stream.Transform {
|
|
|
204
212
|
}
|
|
205
213
|
});
|
|
206
214
|
setImmediate(callback);
|
|
207
|
-
}.bind(this)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this._module.finalize
|
|
219
|
-
|
|
220
|
-
this._module.end
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Pipes the module to our internal stream with error bubbling.
|
|
227
|
-
*
|
|
228
|
-
* @private
|
|
229
|
-
* @return void
|
|
230
|
-
*/
|
|
231
|
-
_modulePipe() {
|
|
232
|
-
this._module.on("error", this._onModuleError.bind(this));
|
|
233
|
-
this._module.pipe(this);
|
|
234
|
-
this._state.modulePiped = true;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Unpipes the module from our internal stream.
|
|
238
|
-
*
|
|
239
|
-
* @private
|
|
240
|
-
* @return void
|
|
241
|
-
*/
|
|
242
|
-
_moduleUnpipe() {
|
|
243
|
-
this._module.unpipe(this);
|
|
244
|
-
this._state.modulePiped = false;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Normalizes entry data with fallbacks for key properties.
|
|
248
|
-
*
|
|
249
|
-
* @private
|
|
250
|
-
* @param {Object} data
|
|
251
|
-
* @param {fs.Stats} stats
|
|
252
|
-
* @return {Object}
|
|
253
|
-
*/
|
|
254
|
-
_normalizeEntryData(data, stats) {
|
|
255
|
-
data = {
|
|
256
|
-
type: "file",
|
|
257
|
-
name: null,
|
|
258
|
-
date: null,
|
|
259
|
-
mode: null,
|
|
260
|
-
prefix: null,
|
|
261
|
-
sourcePath: null,
|
|
262
|
-
stats: false,
|
|
263
|
-
...data
|
|
264
|
-
};
|
|
265
|
-
if (stats && data.stats === false) {
|
|
266
|
-
data.stats = stats;
|
|
267
|
-
}
|
|
268
|
-
let isDir = data.type === "directory";
|
|
269
|
-
if (data.name) {
|
|
270
|
-
if (typeof data.prefix === "string" && "" !== data.prefix) {
|
|
271
|
-
data.name = data.prefix + "/" + data.name;
|
|
272
|
-
data.prefix = null;
|
|
273
|
-
}
|
|
274
|
-
data.name = (0, import_utils.sanitizePath)(data.name);
|
|
275
|
-
if (data.type !== "symlink" && data.name.slice(-1) === "/") {
|
|
276
|
-
isDir = true;
|
|
277
|
-
data.type = "directory";
|
|
278
|
-
} else if (isDir) {
|
|
279
|
-
data.name += "/";
|
|
215
|
+
}.bind(this));
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Finalizes the module.
|
|
219
|
+
*
|
|
220
|
+
* @private
|
|
221
|
+
* @return void
|
|
222
|
+
*/
|
|
223
|
+
}, {
|
|
224
|
+
key: "_moduleFinalize",
|
|
225
|
+
value: function _moduleFinalize() {
|
|
226
|
+
if (typeof this._module.finalize === "function") {
|
|
227
|
+
this._module.finalize();
|
|
228
|
+
} else if (typeof this._module.end === "function") {
|
|
229
|
+
this._module.end();
|
|
230
|
+
} else {
|
|
231
|
+
this.emit("error", new _error.ArchiverError("NOENDMETHOD"));
|
|
280
232
|
}
|
|
281
233
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Pipes the module to our internal stream with error bubbling.
|
|
236
|
+
*
|
|
237
|
+
* @private
|
|
238
|
+
* @return void
|
|
239
|
+
*/
|
|
240
|
+
}, {
|
|
241
|
+
key: "_modulePipe",
|
|
242
|
+
value: function _modulePipe() {
|
|
243
|
+
this._module.on("error", this._onModuleError.bind(this));
|
|
244
|
+
this._module.pipe(this);
|
|
245
|
+
this._state.modulePiped = true;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Unpipes the module from our internal stream.
|
|
249
|
+
*
|
|
250
|
+
* @private
|
|
251
|
+
* @return void
|
|
252
|
+
*/
|
|
253
|
+
}, {
|
|
254
|
+
key: "_moduleUnpipe",
|
|
255
|
+
value: function _moduleUnpipe() {
|
|
256
|
+
this._module.unpipe(this);
|
|
257
|
+
this._state.modulePiped = false;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Normalizes entry data with fallbacks for key properties.
|
|
261
|
+
*
|
|
262
|
+
* @private
|
|
263
|
+
* @param {Object} data
|
|
264
|
+
* @param {fs.Stats} stats
|
|
265
|
+
* @return {Object}
|
|
266
|
+
*/
|
|
267
|
+
}, {
|
|
268
|
+
key: "_normalizeEntryData",
|
|
269
|
+
value: function _normalizeEntryData(data, stats) {
|
|
270
|
+
data = _objectSpread({
|
|
271
|
+
type: "file",
|
|
272
|
+
name: null,
|
|
273
|
+
date: null,
|
|
274
|
+
mode: null,
|
|
275
|
+
prefix: null,
|
|
276
|
+
sourcePath: null,
|
|
277
|
+
stats: false
|
|
278
|
+
}, data);
|
|
279
|
+
if (stats && data.stats === false) {
|
|
280
|
+
data.stats = stats;
|
|
287
281
|
}
|
|
288
|
-
|
|
289
|
-
if (
|
|
290
|
-
data.
|
|
291
|
-
|
|
292
|
-
|
|
282
|
+
var isDir = data.type === "directory";
|
|
283
|
+
if (data.name) {
|
|
284
|
+
if (typeof data.prefix === "string" && "" !== data.prefix) {
|
|
285
|
+
data.name = data.prefix + "/" + data.name;
|
|
286
|
+
data.prefix = null;
|
|
287
|
+
}
|
|
288
|
+
data.name = (0, _utils.sanitizePath)(data.name);
|
|
289
|
+
if (data.type !== "symlink" && data.name.slice(-1) === "/") {
|
|
290
|
+
isDir = true;
|
|
291
|
+
data.type = "directory";
|
|
292
|
+
} else if (isDir) {
|
|
293
|
+
data.name += "/";
|
|
294
|
+
}
|
|
293
295
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
+
// 511 === 0777; 493 === 0755; 438 === 0666; 420 === 0644
|
|
297
|
+
if (typeof data.mode === "number") {
|
|
298
|
+
if (win32) {
|
|
299
|
+
data.mode &= 511;
|
|
300
|
+
} else {
|
|
301
|
+
data.mode &= 4095;
|
|
302
|
+
}
|
|
303
|
+
} else if (data.stats && data.mode === null) {
|
|
304
|
+
if (win32) {
|
|
305
|
+
data.mode = data.stats.mode & 511;
|
|
306
|
+
} else {
|
|
307
|
+
data.mode = data.stats.mode & 4095;
|
|
308
|
+
}
|
|
309
|
+
// stat isn't reliable on windows; force 0755 for dir
|
|
310
|
+
if (win32 && isDir) {
|
|
311
|
+
data.mode = 493;
|
|
312
|
+
}
|
|
313
|
+
} else if (data.mode === null) {
|
|
314
|
+
data.mode = isDir ? 493 : 420;
|
|
296
315
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
data.date = data.stats.mtime;
|
|
302
|
-
} else {
|
|
303
|
-
data.date = (0, import_utils.dateify)(data.date);
|
|
304
|
-
}
|
|
305
|
-
return data;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Error listener that re-emits error on to our internal stream.
|
|
309
|
-
*
|
|
310
|
-
* @private
|
|
311
|
-
* @param {Error} err
|
|
312
|
-
* @return void
|
|
313
|
-
*/
|
|
314
|
-
_onModuleError(err) {
|
|
315
|
-
this.emit("error", err);
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Checks the various state variables after queue has drained to determine if
|
|
319
|
-
* we need to `finalize`.
|
|
320
|
-
*
|
|
321
|
-
* @private
|
|
322
|
-
* @return void
|
|
323
|
-
*/
|
|
324
|
-
_onQueueDrain() {
|
|
325
|
-
if (this._state.finalizing || this._state.finalized || this._state.aborted) {
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
if (this._state.finalize && this._pending === 0 && this._queue.idle() && this._statQueue.idle()) {
|
|
329
|
-
this._finalize();
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Appends each queue task to the module.
|
|
334
|
-
*
|
|
335
|
-
* @private
|
|
336
|
-
* @param {Object} task
|
|
337
|
-
* @param {Function} callback
|
|
338
|
-
* @return void
|
|
339
|
-
*/
|
|
340
|
-
_onQueueTask(task, callback) {
|
|
341
|
-
const fullCallback = () => {
|
|
342
|
-
if (task.data.callback) {
|
|
343
|
-
task.data.callback();
|
|
316
|
+
if (data.stats && data.date === null) {
|
|
317
|
+
data.date = data.stats.mtime;
|
|
318
|
+
} else {
|
|
319
|
+
data.date = (0, _utils.dateify)(data.date);
|
|
344
320
|
}
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
321
|
+
return data;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Error listener that re-emits error on to our internal stream.
|
|
325
|
+
*
|
|
326
|
+
* @private
|
|
327
|
+
* @param {Error} err
|
|
328
|
+
* @return void
|
|
329
|
+
*/
|
|
330
|
+
}, {
|
|
331
|
+
key: "_onModuleError",
|
|
332
|
+
value: function _onModuleError(err) {
|
|
333
|
+
/**
|
|
334
|
+
* @event Archiver#error
|
|
335
|
+
* @type {ErrorData}
|
|
336
|
+
*/
|
|
337
|
+
this.emit("error", err);
|
|
350
338
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
339
|
+
/**
|
|
340
|
+
* Checks the various state variables after queue has drained to determine if
|
|
341
|
+
* we need to `finalize`.
|
|
342
|
+
*
|
|
343
|
+
* @private
|
|
344
|
+
* @return void
|
|
345
|
+
*/
|
|
346
|
+
}, {
|
|
347
|
+
key: "_onQueueDrain",
|
|
348
|
+
value: function _onQueueDrain() {
|
|
349
|
+
if (this._state.finalizing || this._state.finalized || this._state.aborted) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (this._state.finalize && this._pending === 0 && this._queue.idle() && this._statQueue.idle()) {
|
|
353
|
+
this._finalize();
|
|
354
|
+
}
|
|
366
355
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
356
|
+
/**
|
|
357
|
+
* Appends each queue task to the module.
|
|
358
|
+
*
|
|
359
|
+
* @private
|
|
360
|
+
* @param {Object} task
|
|
361
|
+
* @param {Function} callback
|
|
362
|
+
* @return void
|
|
363
|
+
*/
|
|
364
|
+
}, {
|
|
365
|
+
key: "_onQueueTask",
|
|
366
|
+
value: function _onQueueTask(task, callback) {
|
|
367
|
+
var fullCallback = function fullCallback() {
|
|
368
|
+
if (task.data.callback) {
|
|
369
|
+
task.data.callback();
|
|
370
|
+
}
|
|
371
|
+
callback();
|
|
372
|
+
};
|
|
373
|
+
if (this._state.finalizing || this._state.finalized || this._state.aborted) {
|
|
374
|
+
fullCallback();
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
this._task = task;
|
|
378
|
+
this._moduleAppend(task.source, task.data, fullCallback);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Performs a file stat and reinjects the task back into the queue.
|
|
382
|
+
*
|
|
383
|
+
* @private
|
|
384
|
+
* @param {Object} task
|
|
385
|
+
* @param {Function} callback
|
|
386
|
+
* @return void
|
|
387
|
+
*/
|
|
388
|
+
}, {
|
|
389
|
+
key: "_onStatQueueTask",
|
|
390
|
+
value: function _onStatQueueTask(task, callback) {
|
|
391
|
+
if (this._state.finalizing || this._state.finalized || this._state.aborted) {
|
|
392
|
+
callback();
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
(0, _fs.lstat)(task.filepath, function (err, stats) {
|
|
370
396
|
if (this._state.aborted) {
|
|
371
397
|
setImmediate(callback);
|
|
372
398
|
return;
|
|
373
399
|
}
|
|
374
400
|
if (err) {
|
|
375
401
|
this._entriesCount--;
|
|
402
|
+
/**
|
|
403
|
+
* @event Archiver#warning
|
|
404
|
+
* @type {ErrorData}
|
|
405
|
+
*/
|
|
376
406
|
this.emit("warning", err);
|
|
377
407
|
setImmediate(callback);
|
|
378
408
|
return;
|
|
@@ -385,382 +415,441 @@ class Archiver extends import_readable_stream.Transform {
|
|
|
385
415
|
this._queue.push(task);
|
|
386
416
|
}
|
|
387
417
|
setImmediate(callback);
|
|
388
|
-
}.bind(this)
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
(0,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
this.emit(
|
|
450
|
-
"warning",
|
|
451
|
-
new import_error.ArchiverError("DIRECTORYNOTSUPPORTED", task.data)
|
|
452
|
-
);
|
|
453
|
-
} else if (stats.isSymbolicLink()) {
|
|
454
|
-
this.emit(
|
|
455
|
-
"warning",
|
|
456
|
-
new import_error.ArchiverError("SYMLINKNOTSUPPORTED", task.data)
|
|
457
|
-
);
|
|
418
|
+
}.bind(this));
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Unpipes the module and ends our internal stream.
|
|
422
|
+
*
|
|
423
|
+
* @private
|
|
424
|
+
* @return void
|
|
425
|
+
*/
|
|
426
|
+
}, {
|
|
427
|
+
key: "_shutdown",
|
|
428
|
+
value: function _shutdown() {
|
|
429
|
+
this._moduleUnpipe();
|
|
430
|
+
this.end();
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Tracks the bytes emitted by our internal stream.
|
|
434
|
+
*
|
|
435
|
+
* @private
|
|
436
|
+
* @param {Buffer} chunk
|
|
437
|
+
* @param {String} encoding
|
|
438
|
+
* @param {Function} callback
|
|
439
|
+
* @return void
|
|
440
|
+
*/
|
|
441
|
+
}, {
|
|
442
|
+
key: "_transform",
|
|
443
|
+
value: function _transform(chunk, encoding, callback) {
|
|
444
|
+
if (chunk) {
|
|
445
|
+
this._pointer += chunk.length;
|
|
446
|
+
}
|
|
447
|
+
callback(null, chunk);
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Updates and normalizes a queue task using stats data.
|
|
451
|
+
*
|
|
452
|
+
* @private
|
|
453
|
+
* @param {Object} task
|
|
454
|
+
* @param {Stats} stats
|
|
455
|
+
* @return {Object}
|
|
456
|
+
*/
|
|
457
|
+
}, {
|
|
458
|
+
key: "_updateQueueTaskWithStats",
|
|
459
|
+
value: function _updateQueueTaskWithStats(task, stats) {
|
|
460
|
+
if (stats.isFile()) {
|
|
461
|
+
task.data.type = "file";
|
|
462
|
+
task.data.sourceType = "stream";
|
|
463
|
+
task.source = new _lazystream.Readable(function () {
|
|
464
|
+
return (0, _fs.createReadStream)(task.filepath);
|
|
465
|
+
});
|
|
466
|
+
} else if (stats.isDirectory() && this._supportsDirectory) {
|
|
467
|
+
task.data.name = (0, _utils.trailingSlashIt)(task.data.name);
|
|
468
|
+
task.data.type = "directory";
|
|
469
|
+
task.data.sourcePath = (0, _utils.trailingSlashIt)(task.filepath);
|
|
470
|
+
task.data.sourceType = "buffer";
|
|
471
|
+
task.source = Buffer.concat([]);
|
|
472
|
+
} else if (stats.isSymbolicLink() && this._supportsSymlink) {
|
|
473
|
+
var linkPath = (0, _fs.readlinkSync)(task.filepath);
|
|
474
|
+
var dirName = (0, _path.dirname)(task.filepath);
|
|
475
|
+
task.data.type = "symlink";
|
|
476
|
+
task.data.linkname = (0, _path.relative)(dirName, (0, _path.resolve)(dirName, linkPath));
|
|
477
|
+
task.data.sourceType = "buffer";
|
|
478
|
+
task.source = Buffer.concat([]);
|
|
458
479
|
} else {
|
|
459
|
-
|
|
480
|
+
if (stats.isDirectory()) {
|
|
481
|
+
this.emit("warning", new _error.ArchiverError("DIRECTORYNOTSUPPORTED", task.data));
|
|
482
|
+
} else if (stats.isSymbolicLink()) {
|
|
483
|
+
this.emit("warning", new _error.ArchiverError("SYMLINKNOTSUPPORTED", task.data));
|
|
484
|
+
} else {
|
|
485
|
+
this.emit("warning", new _error.ArchiverError("ENTRYNOTSUPPORTED", task.data));
|
|
486
|
+
}
|
|
487
|
+
return null;
|
|
460
488
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return this;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Appends an input source (text string, buffer, or stream) to the instance.
|
|
487
|
-
*
|
|
488
|
-
* When the instance has received, processed, and emitted the input, the `entry`
|
|
489
|
-
* event is fired.
|
|
490
|
-
*
|
|
491
|
-
* @fires Archiver#entry
|
|
492
|
-
* @param {(Buffer|Stream|String)} source The input source.
|
|
493
|
-
* @param {EntryData} data See also {@link ZipEntryData} and {@link TarEntryData}.
|
|
494
|
-
* @return {this}
|
|
495
|
-
*/
|
|
496
|
-
append(source, data) {
|
|
497
|
-
if (this._state.finalize || this._state.aborted) {
|
|
498
|
-
this.emit("error", new import_error.ArchiverError("QUEUECLOSED"));
|
|
499
|
-
return this;
|
|
500
|
-
}
|
|
501
|
-
data = this._normalizeEntryData(data);
|
|
502
|
-
if (typeof data.name !== "string" || data.name.length === 0) {
|
|
503
|
-
this.emit("error", new import_error.ArchiverError("ENTRYNAMEREQUIRED"));
|
|
504
|
-
return this;
|
|
505
|
-
}
|
|
506
|
-
if (data.type === "directory" && !this._supportsDirectory) {
|
|
507
|
-
this.emit(
|
|
508
|
-
"error",
|
|
509
|
-
new import_error.ArchiverError("DIRECTORYNOTSUPPORTED", { name: data.name })
|
|
510
|
-
);
|
|
511
|
-
return this;
|
|
512
|
-
}
|
|
513
|
-
source = (0, import_utils.normalizeInputSource)(source);
|
|
514
|
-
if (Buffer.isBuffer(source)) {
|
|
515
|
-
data.sourceType = "buffer";
|
|
516
|
-
} else if ((0, import_is_stream.isStream)(source)) {
|
|
517
|
-
data.sourceType = "stream";
|
|
518
|
-
} else {
|
|
519
|
-
this.emit(
|
|
520
|
-
"error",
|
|
521
|
-
new import_error.ArchiverError("INPUTSTEAMBUFFERREQUIRED", { name: data.name })
|
|
522
|
-
);
|
|
523
|
-
return this;
|
|
524
|
-
}
|
|
525
|
-
this._entriesCount++;
|
|
526
|
-
this._queue.push({
|
|
527
|
-
data,
|
|
528
|
-
source
|
|
529
|
-
});
|
|
530
|
-
return this;
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Appends a directory and its files, recursively, given its dirpath.
|
|
534
|
-
*
|
|
535
|
-
* @param {String} dirpath The source directory path.
|
|
536
|
-
* @param {String} destpath The destination path within the archive.
|
|
537
|
-
* @param {(EntryData|Function)} data See also [ZipEntryData]{@link ZipEntryData} and
|
|
538
|
-
* [TarEntryData]{@link TarEntryData}.
|
|
539
|
-
* @return {this}
|
|
540
|
-
*/
|
|
541
|
-
directory(dirpath, destpath, data) {
|
|
542
|
-
if (this._state.finalize || this._state.aborted) {
|
|
543
|
-
this.emit("error", new import_error.ArchiverError("QUEUECLOSED"));
|
|
489
|
+
task.data = this._normalizeEntryData(task.data, stats);
|
|
490
|
+
return task;
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Aborts the archiving process, taking a best-effort approach, by:
|
|
494
|
+
*
|
|
495
|
+
* - removing any pending queue tasks
|
|
496
|
+
* - allowing any active queue workers to finish
|
|
497
|
+
* - detaching internal module pipes
|
|
498
|
+
* - ending both sides of the Transform stream
|
|
499
|
+
*
|
|
500
|
+
* It will NOT drain any remaining sources.
|
|
501
|
+
*
|
|
502
|
+
* @return {this}
|
|
503
|
+
*/
|
|
504
|
+
}, {
|
|
505
|
+
key: "abort",
|
|
506
|
+
value: function abort() {
|
|
507
|
+
if (this._state.aborted || this._state.finalized) {
|
|
508
|
+
return this;
|
|
509
|
+
}
|
|
510
|
+
this._abort();
|
|
544
511
|
return this;
|
|
545
512
|
}
|
|
546
|
-
|
|
547
|
-
|
|
513
|
+
/**
|
|
514
|
+
* Appends an input source (text string, buffer, or stream) to the instance.
|
|
515
|
+
*
|
|
516
|
+
* When the instance has received, processed, and emitted the input, the `entry`
|
|
517
|
+
* event is fired.
|
|
518
|
+
*
|
|
519
|
+
* @fires Archiver#entry
|
|
520
|
+
* @param {(Buffer|Stream|String)} source The input source.
|
|
521
|
+
* @param {EntryData} data See also {@link ZipEntryData} and {@link TarEntryData}.
|
|
522
|
+
* @return {this}
|
|
523
|
+
*/
|
|
524
|
+
}, {
|
|
525
|
+
key: "append",
|
|
526
|
+
value: function append(source, data) {
|
|
527
|
+
if (this._state.finalize || this._state.aborted) {
|
|
528
|
+
this.emit("error", new _error.ArchiverError("QUEUECLOSED"));
|
|
529
|
+
return this;
|
|
530
|
+
}
|
|
531
|
+
data = this._normalizeEntryData(data);
|
|
532
|
+
if (typeof data.name !== "string" || data.name.length === 0) {
|
|
533
|
+
this.emit("error", new _error.ArchiverError("ENTRYNAMEREQUIRED"));
|
|
534
|
+
return this;
|
|
535
|
+
}
|
|
536
|
+
if (data.type === "directory" && !this._supportsDirectory) {
|
|
537
|
+
this.emit("error", new _error.ArchiverError("DIRECTORYNOTSUPPORTED", {
|
|
538
|
+
name: data.name
|
|
539
|
+
}));
|
|
540
|
+
return this;
|
|
541
|
+
}
|
|
542
|
+
source = (0, _utils.normalizeInputSource)(source);
|
|
543
|
+
if (Buffer.isBuffer(source)) {
|
|
544
|
+
data.sourceType = "buffer";
|
|
545
|
+
} else if ((0, _isStream.isStream)(source)) {
|
|
546
|
+
data.sourceType = "stream";
|
|
547
|
+
} else {
|
|
548
|
+
this.emit("error", new _error.ArchiverError("INPUTSTEAMBUFFERREQUIRED", {
|
|
549
|
+
name: data.name
|
|
550
|
+
}));
|
|
551
|
+
return this;
|
|
552
|
+
}
|
|
553
|
+
this._entriesCount++;
|
|
554
|
+
this._queue.push({
|
|
555
|
+
data: data,
|
|
556
|
+
source: source
|
|
557
|
+
});
|
|
548
558
|
return this;
|
|
549
559
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
560
|
+
/**
|
|
561
|
+
* Appends a directory and its files, recursively, given its dirpath.
|
|
562
|
+
*
|
|
563
|
+
* @param {String} dirpath The source directory path.
|
|
564
|
+
* @param {String} destpath The destination path within the archive.
|
|
565
|
+
* @param {(EntryData|Function)} data See also [ZipEntryData]{@link ZipEntryData} and
|
|
566
|
+
* [TarEntryData]{@link TarEntryData}.
|
|
567
|
+
* @return {this}
|
|
568
|
+
*/
|
|
569
|
+
}, {
|
|
570
|
+
key: "directory",
|
|
571
|
+
value: function directory(dirpath, destpath, data) {
|
|
572
|
+
if (this._state.finalize || this._state.aborted) {
|
|
573
|
+
this.emit("error", new _error.ArchiverError("QUEUECLOSED"));
|
|
574
|
+
return this;
|
|
575
|
+
}
|
|
576
|
+
if (typeof dirpath !== "string" || dirpath.length === 0) {
|
|
577
|
+
this.emit("error", new _error.ArchiverError("DIRECTORYDIRPATHREQUIRED"));
|
|
578
|
+
return this;
|
|
579
|
+
}
|
|
580
|
+
this._pending++;
|
|
581
|
+
if (destpath === false) {
|
|
582
|
+
destpath = "";
|
|
583
|
+
} else if (typeof destpath !== "string") {
|
|
584
|
+
destpath = dirpath;
|
|
585
|
+
}
|
|
586
|
+
var dataFunction = false;
|
|
587
|
+
if (typeof data === "function") {
|
|
588
|
+
dataFunction = data;
|
|
589
|
+
data = {};
|
|
590
|
+
} else if (_typeof(data) !== "object") {
|
|
591
|
+
data = {};
|
|
592
|
+
}
|
|
593
|
+
var globOptions = {
|
|
594
|
+
stat: true,
|
|
595
|
+
dot: true
|
|
596
|
+
};
|
|
597
|
+
function onGlobEnd() {
|
|
598
|
+
this._pending--;
|
|
599
|
+
this._maybeFinalize();
|
|
600
|
+
}
|
|
601
|
+
function onGlobError(err) {
|
|
602
|
+
this.emit("error", err);
|
|
603
|
+
}
|
|
604
|
+
function onGlobMatch(match) {
|
|
605
|
+
globber.pause();
|
|
606
|
+
var ignoreMatch = false;
|
|
607
|
+
var entryData = Object.assign({}, data);
|
|
608
|
+
entryData.name = match.relative;
|
|
609
|
+
entryData.prefix = destpath;
|
|
610
|
+
entryData.stats = match.stat;
|
|
611
|
+
entryData.callback = globber.resume.bind(globber);
|
|
612
|
+
try {
|
|
613
|
+
if (dataFunction) {
|
|
614
|
+
entryData = dataFunction(entryData);
|
|
615
|
+
if (entryData === false) {
|
|
616
|
+
ignoreMatch = true;
|
|
617
|
+
} else if (_typeof(entryData) !== "object") {
|
|
618
|
+
throw new _error.ArchiverError("DIRECTORYFUNCTIONINVALIDDATA", {
|
|
619
|
+
dirpath: dirpath
|
|
620
|
+
});
|
|
621
|
+
}
|
|
591
622
|
}
|
|
623
|
+
} catch (e) {
|
|
624
|
+
this.emit("error", e);
|
|
625
|
+
return;
|
|
592
626
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
globber.resume();
|
|
599
|
-
return;
|
|
627
|
+
if (ignoreMatch) {
|
|
628
|
+
globber.resume();
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
this._append(match.absolute, entryData);
|
|
600
632
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
globber.on("match", onGlobMatch.bind(this));
|
|
606
|
-
globber.on("end", onGlobEnd.bind(this));
|
|
607
|
-
return this;
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Appends a file given its filepath using a
|
|
611
|
-
* [lazystream]{@link https://github.com/jpommerening/node-lazystream} wrapper to
|
|
612
|
-
* prevent issues with open file limits.
|
|
613
|
-
*
|
|
614
|
-
* When the instance has received, processed, and emitted the file, the `entry`
|
|
615
|
-
* event is fired.
|
|
616
|
-
*
|
|
617
|
-
* @param {String} filepath The source filepath.
|
|
618
|
-
* @param {EntryData} data See also [ZipEntryData]{@link ZipEntryData} and
|
|
619
|
-
* [TarEntryData]{@link TarEntryData}.
|
|
620
|
-
* @return {this}
|
|
621
|
-
*/
|
|
622
|
-
file(filepath, data) {
|
|
623
|
-
if (this._state.finalize || this._state.aborted) {
|
|
624
|
-
this.emit("error", new import_error.ArchiverError("QUEUECLOSED"));
|
|
625
|
-
return this;
|
|
626
|
-
}
|
|
627
|
-
if (typeof filepath !== "string" || filepath.length === 0) {
|
|
628
|
-
this.emit("error", new import_error.ArchiverError("FILEFILEPATHREQUIRED"));
|
|
633
|
+
var globber = (0, _readdirGlob["default"])(dirpath, globOptions);
|
|
634
|
+
globber.on("error", onGlobError.bind(this));
|
|
635
|
+
globber.on("match", onGlobMatch.bind(this));
|
|
636
|
+
globber.on("end", onGlobEnd.bind(this));
|
|
629
637
|
return this;
|
|
630
638
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
this.
|
|
656
|
-
}
|
|
657
|
-
function onGlobMatch(match) {
|
|
658
|
-
globber.pause();
|
|
659
|
-
const entryData = Object.assign({}, data);
|
|
660
|
-
entryData.callback = globber.resume.bind(globber);
|
|
661
|
-
entryData.stats = match.stat;
|
|
662
|
-
entryData.name = match.relative;
|
|
663
|
-
this._append(match.absolute, entryData);
|
|
664
|
-
}
|
|
665
|
-
const globber = new ReaddirGlob(options.cwd || ".", options);
|
|
666
|
-
globber.on("error", onGlobError.bind(this));
|
|
667
|
-
globber.on("match", onGlobMatch.bind(this));
|
|
668
|
-
globber.on("end", onGlobEnd.bind(this));
|
|
669
|
-
return this;
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* Finalizes the instance and prevents further appending to the archive
|
|
673
|
-
* structure (queue will continue til drained).
|
|
674
|
-
*
|
|
675
|
-
* The `end`, `close` or `finish` events on the destination stream may fire
|
|
676
|
-
* right after calling this method so you should set listeners beforehand to
|
|
677
|
-
* properly detect stream completion.
|
|
678
|
-
*
|
|
679
|
-
* @return {Promise}
|
|
680
|
-
*/
|
|
681
|
-
finalize() {
|
|
682
|
-
if (this._state.aborted) {
|
|
683
|
-
var abortedError = new import_error.ArchiverError("ABORTED");
|
|
684
|
-
this.emit("error", abortedError);
|
|
685
|
-
return Promise.reject(abortedError);
|
|
686
|
-
}
|
|
687
|
-
if (this._state.finalize) {
|
|
688
|
-
var finalizingError = new import_error.ArchiverError("FINALIZING");
|
|
689
|
-
this.emit("error", finalizingError);
|
|
690
|
-
return Promise.reject(finalizingError);
|
|
691
|
-
}
|
|
692
|
-
this._state.finalize = true;
|
|
693
|
-
if (this._pending === 0 && this._queue.idle() && this._statQueue.idle()) {
|
|
694
|
-
this._finalize();
|
|
695
|
-
}
|
|
696
|
-
var self = this;
|
|
697
|
-
return new Promise(function(resolve, reject) {
|
|
698
|
-
var errored;
|
|
699
|
-
self._module.on("end", function() {
|
|
700
|
-
if (!errored) {
|
|
701
|
-
resolve();
|
|
702
|
-
}
|
|
703
|
-
});
|
|
704
|
-
self._module.on("error", function(err) {
|
|
705
|
-
errored = true;
|
|
706
|
-
reject(err);
|
|
707
|
-
});
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* Appends a symlink to the instance.
|
|
712
|
-
*
|
|
713
|
-
* This does NOT interact with filesystem and is used for programmatically creating symlinks.
|
|
714
|
-
*
|
|
715
|
-
* @param {String} filepath The symlink path (within archive).
|
|
716
|
-
* @param {String} target The target path (within archive).
|
|
717
|
-
* @param {Number} mode Sets the entry permissions.
|
|
718
|
-
* @return {this}
|
|
719
|
-
*/
|
|
720
|
-
symlink(filepath, target, mode) {
|
|
721
|
-
if (this._state.finalize || this._state.aborted) {
|
|
722
|
-
this.emit("error", new import_error.ArchiverError("QUEUECLOSED"));
|
|
639
|
+
/**
|
|
640
|
+
* Appends a file given its filepath using a
|
|
641
|
+
* [lazystream]{@link https://github.com/jpommerening/node-lazystream} wrapper to
|
|
642
|
+
* prevent issues with open file limits.
|
|
643
|
+
*
|
|
644
|
+
* When the instance has received, processed, and emitted the file, the `entry`
|
|
645
|
+
* event is fired.
|
|
646
|
+
*
|
|
647
|
+
* @param {String} filepath The source filepath.
|
|
648
|
+
* @param {EntryData} data See also [ZipEntryData]{@link ZipEntryData} and
|
|
649
|
+
* [TarEntryData]{@link TarEntryData}.
|
|
650
|
+
* @return {this}
|
|
651
|
+
*/
|
|
652
|
+
}, {
|
|
653
|
+
key: "file",
|
|
654
|
+
value: function file(filepath, data) {
|
|
655
|
+
if (this._state.finalize || this._state.aborted) {
|
|
656
|
+
this.emit("error", new _error.ArchiverError("QUEUECLOSED"));
|
|
657
|
+
return this;
|
|
658
|
+
}
|
|
659
|
+
if (typeof filepath !== "string" || filepath.length === 0) {
|
|
660
|
+
this.emit("error", new _error.ArchiverError("FILEFILEPATHREQUIRED"));
|
|
661
|
+
return this;
|
|
662
|
+
}
|
|
663
|
+
this._append(filepath, data);
|
|
723
664
|
return this;
|
|
724
665
|
}
|
|
725
|
-
|
|
726
|
-
|
|
666
|
+
/**
|
|
667
|
+
* Appends multiple files that match a glob pattern.
|
|
668
|
+
*
|
|
669
|
+
* @param {String} pattern The [glob pattern]{@link https://github.com/isaacs/minimatch} to match.
|
|
670
|
+
* @param {Object} options See [node-readdir-glob]{@link https://github.com/yqnn/node-readdir-glob#options}.
|
|
671
|
+
* @param {EntryData} data See also [ZipEntryData]{@link ZipEntryData} and
|
|
672
|
+
* [TarEntryData]{@link TarEntryData}.
|
|
673
|
+
* @return {this}
|
|
674
|
+
*/
|
|
675
|
+
}, {
|
|
676
|
+
key: "glob",
|
|
677
|
+
value: function glob(pattern, options, data) {
|
|
678
|
+
this._pending++;
|
|
679
|
+
options = _objectSpread({
|
|
680
|
+
stat: true,
|
|
681
|
+
pattern: pattern
|
|
682
|
+
}, options);
|
|
683
|
+
function onGlobEnd() {
|
|
684
|
+
this._pending--;
|
|
685
|
+
this._maybeFinalize();
|
|
686
|
+
}
|
|
687
|
+
function onGlobError(err) {
|
|
688
|
+
this.emit("error", err);
|
|
689
|
+
}
|
|
690
|
+
function onGlobMatch(match) {
|
|
691
|
+
globber.pause();
|
|
692
|
+
var entryData = Object.assign({}, data);
|
|
693
|
+
entryData.callback = globber.resume.bind(globber);
|
|
694
|
+
entryData.stats = match.stat;
|
|
695
|
+
entryData.name = match.relative;
|
|
696
|
+
this._append(match.absolute, entryData);
|
|
697
|
+
}
|
|
698
|
+
var globber = new ReaddirGlob(options.cwd || ".", options);
|
|
699
|
+
globber.on("error", onGlobError.bind(this));
|
|
700
|
+
globber.on("match", onGlobMatch.bind(this));
|
|
701
|
+
globber.on("end", onGlobEnd.bind(this));
|
|
727
702
|
return this;
|
|
728
703
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
704
|
+
/**
|
|
705
|
+
* Finalizes the instance and prevents further appending to the archive
|
|
706
|
+
* structure (queue will continue til drained).
|
|
707
|
+
*
|
|
708
|
+
* The `end`, `close` or `finish` events on the destination stream may fire
|
|
709
|
+
* right after calling this method so you should set listeners beforehand to
|
|
710
|
+
* properly detect stream completion.
|
|
711
|
+
*
|
|
712
|
+
* @return {Promise}
|
|
713
|
+
*/
|
|
714
|
+
}, {
|
|
715
|
+
key: "finalize",
|
|
716
|
+
value: function finalize() {
|
|
717
|
+
if (this._state.aborted) {
|
|
718
|
+
var abortedError = new _error.ArchiverError("ABORTED");
|
|
719
|
+
this.emit("error", abortedError);
|
|
720
|
+
return Promise.reject(abortedError);
|
|
721
|
+
}
|
|
722
|
+
if (this._state.finalize) {
|
|
723
|
+
var finalizingError = new _error.ArchiverError("FINALIZING");
|
|
724
|
+
this.emit("error", finalizingError);
|
|
725
|
+
return Promise.reject(finalizingError);
|
|
726
|
+
}
|
|
727
|
+
this._state.finalize = true;
|
|
728
|
+
if (this._pending === 0 && this._queue.idle() && this._statQueue.idle()) {
|
|
729
|
+
this._finalize();
|
|
730
|
+
}
|
|
731
|
+
var self = this;
|
|
732
|
+
return new Promise(function (resolve, reject) {
|
|
733
|
+
var errored;
|
|
734
|
+
self._module.on("end", function () {
|
|
735
|
+
if (!errored) {
|
|
736
|
+
resolve();
|
|
737
|
+
}
|
|
738
|
+
});
|
|
739
|
+
self._module.on("error", function (err) {
|
|
740
|
+
errored = true;
|
|
741
|
+
reject(err);
|
|
742
|
+
});
|
|
743
|
+
});
|
|
735
744
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
745
|
+
/**
|
|
746
|
+
* Appends a symlink to the instance.
|
|
747
|
+
*
|
|
748
|
+
* This does NOT interact with filesystem and is used for programmatically creating symlinks.
|
|
749
|
+
*
|
|
750
|
+
* @param {String} filepath The symlink path (within archive).
|
|
751
|
+
* @param {String} target The target path (within archive).
|
|
752
|
+
* @param {Number} mode Sets the entry permissions.
|
|
753
|
+
* @return {this}
|
|
754
|
+
*/
|
|
755
|
+
}, {
|
|
756
|
+
key: "symlink",
|
|
757
|
+
value: function symlink(filepath, target, mode) {
|
|
758
|
+
if (this._state.finalize || this._state.aborted) {
|
|
759
|
+
this.emit("error", new _error.ArchiverError("QUEUECLOSED"));
|
|
760
|
+
return this;
|
|
761
|
+
}
|
|
762
|
+
if (typeof filepath !== "string" || filepath.length === 0) {
|
|
763
|
+
this.emit("error", new _error.ArchiverError("SYMLINKFILEPATHREQUIRED"));
|
|
764
|
+
return this;
|
|
765
|
+
}
|
|
766
|
+
if (typeof target !== "string" || target.length === 0) {
|
|
767
|
+
this.emit("error", new _error.ArchiverError("SYMLINKTARGETREQUIRED", {
|
|
768
|
+
filepath: filepath
|
|
769
|
+
}));
|
|
770
|
+
return this;
|
|
771
|
+
}
|
|
772
|
+
if (!this._supportsSymlink) {
|
|
773
|
+
this.emit("error", new _error.ArchiverError("SYMLINKNOTSUPPORTED", {
|
|
774
|
+
filepath: filepath
|
|
775
|
+
}));
|
|
776
|
+
return this;
|
|
777
|
+
}
|
|
778
|
+
var data = {};
|
|
779
|
+
data.type = "symlink";
|
|
780
|
+
data.name = filepath.replace(/\\/g, "/");
|
|
781
|
+
data.linkname = target.replace(/\\/g, "/");
|
|
782
|
+
data.sourceType = "buffer";
|
|
783
|
+
if (typeof mode === "number") {
|
|
784
|
+
data.mode = mode;
|
|
785
|
+
}
|
|
786
|
+
this._entriesCount++;
|
|
787
|
+
this._queue.push({
|
|
788
|
+
data: data,
|
|
789
|
+
source: Buffer.concat([])
|
|
790
|
+
});
|
|
741
791
|
return this;
|
|
742
792
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
}
|
|
793
|
+
/**
|
|
794
|
+
* Returns the current length (in bytes) that has been emitted.
|
|
795
|
+
*
|
|
796
|
+
* @return {Number}
|
|
797
|
+
*/
|
|
798
|
+
}, {
|
|
799
|
+
key: "pointer",
|
|
800
|
+
value: function pointer() {
|
|
801
|
+
return this._pointer;
|
|
802
|
+
}
|
|
803
|
+
}]);
|
|
804
|
+
}(_readableStream.Transform);
|
|
805
|
+
/**
|
|
806
|
+
* @typedef {Object} CoreOptions
|
|
807
|
+
* @global
|
|
808
|
+
* @property {Number} [statConcurrency=4] Sets the number of workers used to
|
|
809
|
+
* process the internal fs stat queue.
|
|
810
|
+
*/
|
|
811
|
+
/**
|
|
812
|
+
* @typedef {Object} TransformOptions
|
|
813
|
+
* @property {Boolean} [allowHalfOpen=true] If set to false, then the stream
|
|
814
|
+
* will automatically end the readable side when the writable side ends and vice
|
|
815
|
+
* versa.
|
|
816
|
+
* @property {Boolean} [readableObjectMode=false] Sets objectMode for readable
|
|
817
|
+
* side of the stream. Has no effect if objectMode is true.
|
|
818
|
+
* @property {Boolean} [writableObjectMode=false] Sets objectMode for writable
|
|
819
|
+
* side of the stream. Has no effect if objectMode is true.
|
|
820
|
+
* @property {Boolean} [decodeStrings=true] Whether or not to decode strings
|
|
821
|
+
* into Buffers before passing them to _write(). `Writable`
|
|
822
|
+
* @property {String} [encoding=NULL] If specified, then buffers will be decoded
|
|
823
|
+
* to strings using the specified encoding. `Readable`
|
|
824
|
+
* @property {Number} [highWaterMark=16kb] The maximum number of bytes to store
|
|
825
|
+
* in the internal buffer before ceasing to read from the underlying resource.
|
|
826
|
+
* `Readable` `Writable`
|
|
827
|
+
* @property {Boolean} [objectMode=false] Whether this stream should behave as a
|
|
828
|
+
* stream of objects. Meaning that stream.read(n) returns a single value instead
|
|
829
|
+
* of a Buffer of size n. `Readable` `Writable`
|
|
830
|
+
*/
|
|
831
|
+
/**
|
|
832
|
+
* @typedef {Object} EntryData
|
|
833
|
+
* @property {String} name Sets the entry name including internal path.
|
|
834
|
+
* @property {(String|Date)} [date=NOW()] Sets the entry date.
|
|
835
|
+
* @property {Number} [mode=D:0755/F:0644] Sets the entry permissions.
|
|
836
|
+
* @property {String} [prefix] Sets a path prefix for the entry name. Useful
|
|
837
|
+
* when working with methods like `directory` or `glob`.
|
|
838
|
+
* @property {fs.Stats} [stats] Sets the fs stat data for this entry allowing
|
|
839
|
+
* for reduction of fs stat calls when stat data is already known.
|
|
840
|
+
*/
|
|
841
|
+
/**
|
|
842
|
+
* @typedef {Object} ErrorData
|
|
843
|
+
* @property {String} message The message of the error.
|
|
844
|
+
* @property {String} code The error code assigned to this error.
|
|
845
|
+
* @property {String} data Additional data provided for reporting or debugging (where available).
|
|
846
|
+
*/
|
|
847
|
+
/**
|
|
848
|
+
* @typedef {Object} ProgressData
|
|
849
|
+
* @property {Object} entries
|
|
850
|
+
* @property {Number} entries.total Number of entries that have been appended.
|
|
851
|
+
* @property {Number} entries.processed Number of entries that have been processed.
|
|
852
|
+
* @property {Object} fs
|
|
853
|
+
* @property {Number} fs.totalBytes Number of bytes that have been appended. Calculated asynchronously and might not be accurate: it growth while entries are added. (based on fs.Stats)
|
|
854
|
+
* @property {Number} fs.processedBytes Number of bytes that have been processed. (based on fs.Stats)
|
|
855
|
+
*/
|