archiver-node 8.0.2 → 8.0.4

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