tar-iterator 0.2.9 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/FileEntry.js +62 -0
- package/dist/cjs/FileEntry.js.map +1 -0
- package/dist/cjs/TarIterator.js +80 -0
- package/dist/cjs/TarIterator.js.map +1 -0
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/Lock.js +20 -0
- package/dist/cjs/lib/Lock.js.map +1 -0
- package/dist/cjs/lib/fifoRemove.js +16 -0
- package/dist/cjs/lib/fifoRemove.js.map +1 -0
- package/dist/cjs/lib/waitForAccess.js +15 -0
- package/dist/cjs/lib/waitForAccess.js.map +1 -0
- package/dist/cjs/nextEntry.js +60 -0
- package/dist/cjs/nextEntry.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/types/FileEntry.d.cts +10 -0
- package/dist/types/TarIterator.d.cts +8 -0
- package/dist/types/index.d.mts +2 -0
- package/dist/types/lib/Lock.d.cts +2 -0
- package/dist/types/lib/fifoRemove.d.cts +2 -0
- package/dist/types/lib/waitForAccess.d.cts +2 -0
- package/dist/types/nextEntry.d.cts +2 -0
- package/package.json +24 -22
- package/lib/FileEntry.js +0 -65
- package/lib/TarIterator.js +0 -75
- package/lib/index.js +0 -7
- package/lib/lib/Lock.js +0 -14
- package/lib/lib/fifoRemove.js +0 -9
- package/lib/lib/waitForAccess.js +0 -10
- package/lib/nextEntry.js +0 -64
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var inherits = require("inherits");
|
|
3
|
+
var BaseIterator = require("extract-base-iterator").default;
|
|
4
|
+
var fs = require("fs");
|
|
5
|
+
var eos = require("end-of-stream");
|
|
6
|
+
var waitForAccess = require("./lib/waitForAccess.js");
|
|
7
|
+
function FileEntry(attributes, stream, lock) {
|
|
8
|
+
BaseIterator.FileEntry.call(this, attributes);
|
|
9
|
+
this.stream = stream;
|
|
10
|
+
this.lock = lock;
|
|
11
|
+
this.lock.retain();
|
|
12
|
+
}
|
|
13
|
+
inherits(FileEntry, BaseIterator.FileEntry);
|
|
14
|
+
FileEntry.prototype.create = function create(dest, options, callback) {
|
|
15
|
+
if (typeof options === "function") {
|
|
16
|
+
callback = options;
|
|
17
|
+
options = null;
|
|
18
|
+
}
|
|
19
|
+
var self = this;
|
|
20
|
+
if (typeof callback === "function") {
|
|
21
|
+
options = options || {};
|
|
22
|
+
return BaseIterator.FileEntry.prototype.create.call(this, dest, options, function createCallback(err) {
|
|
23
|
+
callback(err);
|
|
24
|
+
if (self.lock) {
|
|
25
|
+
self.lock.release();
|
|
26
|
+
self.lock = null;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return new Promise(function createPromise(resolve, reject) {
|
|
31
|
+
self.create(dest, options, function createCallback(err, done) {
|
|
32
|
+
err ? reject(err) : resolve(done);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
FileEntry.prototype._writeFile = function _writeFile(fullPath, _options, callback) {
|
|
37
|
+
if (!this.stream) return callback(new Error("Zip FileEntry missing stream. Check for calling create multiple times"));
|
|
38
|
+
var stream = this.stream;
|
|
39
|
+
this.stream = null;
|
|
40
|
+
var res = stream.pipe(fs.createWriteStream(fullPath));
|
|
41
|
+
eos(res, function(err) {
|
|
42
|
+
err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occassionally
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
FileEntry.prototype.destroy = function destroy() {
|
|
46
|
+
BaseIterator.FileEntry.prototype.destroy.call(this);
|
|
47
|
+
if (this.stream) {
|
|
48
|
+
this.stream.resume(); // drain stream
|
|
49
|
+
this.stream = null;
|
|
50
|
+
}
|
|
51
|
+
if (this.lock) {
|
|
52
|
+
this.lock.release();
|
|
53
|
+
this.lock = null;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
module.exports = FileEntry;
|
|
57
|
+
|
|
58
|
+
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
59
|
+
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
60
|
+
for (var key in exports) exports.default[key] = exports[key];
|
|
61
|
+
module.exports = exports.default;
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["FileEntry.cjs"],"sourcesContent":["const inherits = require('inherits');\nconst BaseIterator = require('extract-base-iterator').default;\nconst fs = require('fs');\nconst eos = require('end-of-stream');\n\nconst waitForAccess = require('./lib/waitForAccess.cjs');\n\nfunction FileEntry(attributes, stream, lock) {\n BaseIterator.FileEntry.call(this, attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n}\n\ninherits(FileEntry, BaseIterator.FileEntry);\n\nFileEntry.prototype.create = function create(dest, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n\n const self = this;\n if (typeof callback === 'function') {\n options = options || {};\n return BaseIterator.FileEntry.prototype.create.call(this, dest, options, function createCallback(err) {\n callback(err);\n if (self.lock) {\n self.lock.release();\n self.lock = null;\n }\n });\n }\n\n return new Promise(function createPromise(resolve, reject) {\n self.create(dest, options, function createCallback(err, done) {\n err ? reject(err) : resolve(done);\n });\n });\n};\n\nFileEntry.prototype._writeFile = function _writeFile(fullPath, _options, callback) {\n if (!this.stream) return callback(new Error('Zip FileEntry missing stream. Check for calling create multiple times'));\n\n const stream = this.stream;\n this.stream = null;\n const res = stream.pipe(fs.createWriteStream(fullPath));\n eos(res, (err) => {\n err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occassionally\n });\n};\n\nFileEntry.prototype.destroy = function destroy() {\n BaseIterator.FileEntry.prototype.destroy.call(this);\n if (this.stream) {\n this.stream.resume(); // drain stream\n this.stream = null;\n }\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n};\n\nmodule.exports = FileEntry;\n"],"names":["inherits","require","BaseIterator","default","fs","eos","waitForAccess","FileEntry","attributes","stream","lock","call","retain","prototype","create","dest","options","callback","self","createCallback","err","release","Promise","createPromise","resolve","reject","done","_writeFile","fullPath","_options","Error","res","pipe","createWriteStream","destroy","resume","module","exports"],"mappings":";AAAA,IAAMA,WAAWC,QAAQ;AACzB,IAAMC,eAAeD,QAAQ,yBAAyBE,OAAO;AAC7D,IAAMC,KAAKH,QAAQ;AACnB,IAAMI,MAAMJ,QAAQ;AAEpB,IAAMK,gBAAgBL,QAAQ;AAE9B,SAASM,UAAUC,UAAU,EAAEC,MAAM,EAAEC,IAAI;IACzCR,aAAaK,SAAS,CAACI,IAAI,CAAC,IAAI,EAAEH;IAClC,IAAI,CAACC,MAAM,GAAGA;IACd,IAAI,CAACC,IAAI,GAAGA;IACZ,IAAI,CAACA,IAAI,CAACE,MAAM;AAClB;AAEAZ,SAASO,WAAWL,aAAaK,SAAS;AAE1CA,UAAUM,SAAS,CAACC,MAAM,GAAG,SAASA,OAAOC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAClE,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU;IACZ;IAEA,IAAME,OAAO,IAAI;IACjB,IAAI,OAAOD,aAAa,YAAY;QAClCD,UAAUA,WAAW,CAAC;QACtB,OAAOd,aAAaK,SAAS,CAACM,SAAS,CAACC,MAAM,CAACH,IAAI,CAAC,IAAI,EAAEI,MAAMC,SAAS,SAASG,eAAeC,GAAG;YAClGH,SAASG;YACT,IAAIF,KAAKR,IAAI,EAAE;gBACbQ,KAAKR,IAAI,CAACW,OAAO;gBACjBH,KAAKR,IAAI,GAAG;YACd;QACF;IACF;IAEA,OAAO,IAAIY,QAAQ,SAASC,cAAcC,OAAO,EAAEC,MAAM;QACvDP,KAAKJ,MAAM,CAACC,MAAMC,SAAS,SAASG,eAAeC,GAAG,EAAEM,IAAI;YAC1DN,MAAMK,OAAOL,OAAOI,QAAQE;QAC9B;IACF;AACF;AAEAnB,UAAUM,SAAS,CAACc,UAAU,GAAG,SAASA,WAAWC,QAAQ,EAAEC,QAAQ,EAAEZ,QAAQ;IAC/E,IAAI,CAAC,IAAI,CAACR,MAAM,EAAE,OAAOQ,SAAS,IAAIa,MAAM;IAE5C,IAAMrB,SAAS,IAAI,CAACA,MAAM;IAC1B,IAAI,CAACA,MAAM,GAAG;IACd,IAAMsB,MAAMtB,OAAOuB,IAAI,CAAC5B,GAAG6B,iBAAiB,CAACL;IAC7CvB,IAAI0B,KAAK,SAACX;QACRA,MAAMH,SAASG,OAAOd,cAAcsB,UAAUX,WAAW,kDAAkD;IAC7G;AACF;AAEAV,UAAUM,SAAS,CAACqB,OAAO,GAAG,SAASA;IACrChC,aAAaK,SAAS,CAACM,SAAS,CAACqB,OAAO,CAACvB,IAAI,CAAC,IAAI;IAClD,IAAI,IAAI,CAACF,MAAM,EAAE;QACf,IAAI,CAACA,MAAM,CAAC0B,MAAM,IAAI,eAAe;QACrC,IAAI,CAAC1B,MAAM,GAAG;IAChB;IACA,IAAI,IAAI,CAACC,IAAI,EAAE;QACb,IAAI,CAACA,IAAI,CAACW,OAAO;QACjB,IAAI,CAACX,IAAI,GAAG;IACd;AACF;AAEA0B,OAAOC,OAAO,GAAG9B"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _instanceof(left, right) {
|
|
3
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
4
|
+
return !!right[Symbol.hasInstance](left);
|
|
5
|
+
} else {
|
|
6
|
+
return left instanceof right;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
var inherits = require("inherits");
|
|
10
|
+
var fs = require("fs");
|
|
11
|
+
var tarStream = require("tar-stream-compat");
|
|
12
|
+
var eos = require("end-of-stream");
|
|
13
|
+
var Queue = require("queue-cb");
|
|
14
|
+
var BaseIterator = require("extract-base-iterator").default;
|
|
15
|
+
var nextEntry = require("./nextEntry.js");
|
|
16
|
+
var fifoRemove = require("./lib/fifoRemove.js");
|
|
17
|
+
var Lock = require("./lib/Lock.js");
|
|
18
|
+
function TarIterator(source, options) {
|
|
19
|
+
var _this = this;
|
|
20
|
+
if (!_instanceof(this, TarIterator)) return new TarIterator(source, options);
|
|
21
|
+
BaseIterator.call(this, options);
|
|
22
|
+
this.lock = new Lock();
|
|
23
|
+
this.lock.iterator = this;
|
|
24
|
+
var queue = Queue(1);
|
|
25
|
+
var cancelled = false;
|
|
26
|
+
function setup() {
|
|
27
|
+
cancelled = true;
|
|
28
|
+
}
|
|
29
|
+
this.processing.push(setup);
|
|
30
|
+
this.extract = tarStream.extract();
|
|
31
|
+
if (typeof source === "string") source = fs.createReadStream(source);
|
|
32
|
+
queue.defer(function(callback) {
|
|
33
|
+
var cleanup = function cleanup() {
|
|
34
|
+
source.removeListener("error", onError);
|
|
35
|
+
source.removeListener("data", onData);
|
|
36
|
+
};
|
|
37
|
+
var onError = function onError(err) {
|
|
38
|
+
data = err;
|
|
39
|
+
cleanup();
|
|
40
|
+
callback(err);
|
|
41
|
+
};
|
|
42
|
+
var onData = function onData() {
|
|
43
|
+
data = true;
|
|
44
|
+
cleanup();
|
|
45
|
+
callback();
|
|
46
|
+
};
|
|
47
|
+
var data = null;
|
|
48
|
+
source.on("error", onError);
|
|
49
|
+
source.on("data", onData);
|
|
50
|
+
eos(source.pipe(_this.extract), function(err) {
|
|
51
|
+
if (data) return;
|
|
52
|
+
cleanup();
|
|
53
|
+
callback(err);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
// start processing
|
|
57
|
+
queue.await(function(err) {
|
|
58
|
+
fifoRemove(_this.processing, setup);
|
|
59
|
+
if (_this.done || cancelled) return; // done
|
|
60
|
+
err ? _this.end(err) : _this.push(nextEntry.bind(null, null));
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
inherits(TarIterator, BaseIterator);
|
|
64
|
+
TarIterator.prototype.end = function end(err) {
|
|
65
|
+
if (this.lock) {
|
|
66
|
+
this.lock.err = err;
|
|
67
|
+
this.lock.release();
|
|
68
|
+
this.lock = null;
|
|
69
|
+
} else {
|
|
70
|
+
BaseIterator.prototype.end.call(this, err); // call in lock release so end is properly handled
|
|
71
|
+
}
|
|
72
|
+
this.extract = null;
|
|
73
|
+
};
|
|
74
|
+
module.exports = TarIterator;
|
|
75
|
+
|
|
76
|
+
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
77
|
+
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
78
|
+
for (var key in exports) exports.default[key] = exports[key];
|
|
79
|
+
module.exports = exports.default;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["TarIterator.cjs"],"sourcesContent":["const inherits = require('inherits');\nconst fs = require('fs');\nconst tarStream = require('tar-stream-compat');\nconst eos = require('end-of-stream');\nconst Queue = require('queue-cb');\nconst BaseIterator = require('extract-base-iterator').default;\n\nconst nextEntry = require('./nextEntry.cjs');\nconst fifoRemove = require('./lib/fifoRemove.cjs');\nconst Lock = require('./lib/Lock.cjs');\n\nfunction TarIterator(source, options) {\n if (!(this instanceof TarIterator)) return new TarIterator(source, options);\n BaseIterator.call(this, options);\n this.lock = new Lock();\n this.lock.iterator = this;\n\n const queue = Queue(1);\n let cancelled = false;\n function setup() {\n cancelled = true;\n }\n this.processing.push(setup);\n this.extract = tarStream.extract();\n\n if (typeof source === 'string') source = fs.createReadStream(source);\n queue.defer((callback) => {\n let data = null;\n function cleanup() {\n source.removeListener('error', onError);\n source.removeListener('data', onData);\n }\n function onError(err) {\n data = err;\n cleanup();\n callback(err);\n }\n function onData() {\n data = true;\n cleanup();\n callback();\n }\n source.on('error', onError);\n source.on('data', onData);\n eos(source.pipe(this.extract), (err) => {\n if (data) return;\n cleanup();\n callback(err);\n });\n });\n\n // start processing\n queue.await((err) => {\n fifoRemove(this.processing, setup);\n if (this.done || cancelled) return; // done\n err ? this.end(err) : this.push(nextEntry.bind(null, null));\n });\n}\n\ninherits(TarIterator, BaseIterator);\n\nTarIterator.prototype.end = function end(err) {\n if (this.lock) {\n this.lock.err = err;\n this.lock.release();\n this.lock = null;\n } else {\n BaseIterator.prototype.end.call(this, err); // call in lock release so end is properly handled\n }\n this.extract = null;\n};\n\nmodule.exports = TarIterator;\n"],"names":["inherits","require","fs","tarStream","eos","Queue","BaseIterator","default","nextEntry","fifoRemove","Lock","TarIterator","source","options","call","lock","iterator","queue","cancelled","setup","processing","push","extract","createReadStream","defer","callback","cleanup","removeListener","onError","onData","err","data","on","pipe","await","done","end","bind","prototype","release","module","exports"],"mappings":";;;;;;;;AAAA,IAAMA,WAAWC,QAAQ;AACzB,IAAMC,KAAKD,QAAQ;AACnB,IAAME,YAAYF,QAAQ;AAC1B,IAAMG,MAAMH,QAAQ;AACpB,IAAMI,QAAQJ,QAAQ;AACtB,IAAMK,eAAeL,QAAQ,yBAAyBM,OAAO;AAE7D,IAAMC,YAAYP,QAAQ;AAC1B,IAAMQ,aAAaR,QAAQ;AAC3B,IAAMS,OAAOT,QAAQ;AAErB,SAASU,YAAYC,MAAM,EAAEC,OAAO;;IAClC,IAAI,CAAE,AAAI,YAAJ,IAAI,EAAYF,cAAc,OAAO,IAAIA,YAAYC,QAAQC;IACnEP,aAAaQ,IAAI,CAAC,IAAI,EAAED;IACxB,IAAI,CAACE,IAAI,GAAG,IAAIL;IAChB,IAAI,CAACK,IAAI,CAACC,QAAQ,GAAG,IAAI;IAEzB,IAAMC,QAAQZ,MAAM;IACpB,IAAIa,YAAY;IAChB,SAASC;QACPD,YAAY;IACd;IACA,IAAI,CAACE,UAAU,CAACC,IAAI,CAACF;IACrB,IAAI,CAACG,OAAO,GAAGnB,UAAUmB,OAAO;IAEhC,IAAI,OAAOV,WAAW,UAAUA,SAASV,GAAGqB,gBAAgB,CAACX;IAC7DK,MAAMO,KAAK,CAAC,SAACC;YAEFC,UAAT,SAASA;YACPd,OAAOe,cAAc,CAAC,SAASC;YAC/BhB,OAAOe,cAAc,CAAC,QAAQE;QAChC;YACSD,UAAT,SAASA,QAAQE,GAAG;YAClBC,OAAOD;YACPJ;YACAD,SAASK;QACX;YACSD,SAAT,SAASA;YACPE,OAAO;YACPL;YACAD;QACF;QAdA,IAAIM,OAAO;QAeXnB,OAAOoB,EAAE,CAAC,SAASJ;QACnBhB,OAAOoB,EAAE,CAAC,QAAQH;QAClBzB,IAAIQ,OAAOqB,IAAI,CAAC,MAAKX,OAAO,GAAG,SAACQ;YAC9B,IAAIC,MAAM;YACVL;YACAD,SAASK;QACX;IACF;IAEA,mBAAmB;IACnBb,MAAMiB,KAAK,CAAC,SAACJ;QACXrB,WAAW,MAAKW,UAAU,EAAED;QAC5B,IAAI,MAAKgB,IAAI,IAAIjB,WAAW,QAAQ,OAAO;QAC3CY,MAAM,MAAKM,GAAG,CAACN,OAAO,MAAKT,IAAI,CAACb,UAAU6B,IAAI,CAAC,MAAM;IACvD;AACF;AAEArC,SAASW,aAAaL;AAEtBK,YAAY2B,SAAS,CAACF,GAAG,GAAG,SAASA,IAAIN,GAAG;IAC1C,IAAI,IAAI,CAACf,IAAI,EAAE;QACb,IAAI,CAACA,IAAI,CAACe,GAAG,GAAGA;QAChB,IAAI,CAACf,IAAI,CAACwB,OAAO;QACjB,IAAI,CAACxB,IAAI,GAAG;IACd,OAAO;QACLT,aAAagC,SAAS,CAACF,GAAG,CAACtB,IAAI,CAAC,IAAI,EAAEgB,MAAM,kDAAkD;IAChG;IACA,IAAI,CAACR,OAAO,GAAG;AACjB;AAEAkB,OAAOC,OAAO,GAAG9B"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _extractbaseiterator = /*#__PURE__*/ _interop_require_default(require("extract-base-iterator"));
|
|
12
|
+
var _TarIteratorcjs = /*#__PURE__*/ _interop_require_default(require("./TarIterator.js"));
|
|
13
|
+
function _interop_require_default(obj) {
|
|
14
|
+
return obj && obj.__esModule ? obj : {
|
|
15
|
+
default: obj
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
_TarIteratorcjs.default.DirectoryEntry = _extractbaseiterator.default.DirectoryEntry;
|
|
19
|
+
_TarIteratorcjs.default.FileEntry = require("./FileEntry.js");
|
|
20
|
+
_TarIteratorcjs.default.LinkEntry = _extractbaseiterator.default.LinkEntry;
|
|
21
|
+
_TarIteratorcjs.default.SymbolicLinkEntry = _extractbaseiterator.default.SymbolicLinkEntry;
|
|
22
|
+
var _default = _TarIteratorcjs.default;
|
|
23
|
+
|
|
24
|
+
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
25
|
+
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
26
|
+
for (var key in exports) exports.default[key] = exports[key];
|
|
27
|
+
module.exports = exports.default;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.mjs"],"sourcesContent":["import BaseIterator from 'extract-base-iterator';\nimport TarIterator from './TarIterator.cjs';\n\nTarIterator.DirectoryEntry = BaseIterator.DirectoryEntry;\nTarIterator.FileEntry = require('./FileEntry.cjs');\nTarIterator.LinkEntry = BaseIterator.LinkEntry;\nTarIterator.SymbolicLinkEntry = BaseIterator.SymbolicLinkEntry;\nexport default TarIterator;\n"],"names":["TarIterator","DirectoryEntry","BaseIterator","FileEntry","require","LinkEntry","SymbolicLinkEntry"],"mappings":";;;;+BAOA;;;eAAA;;;0EAPyB;qEACD;;;;;;AAExBA,uBAAW,CAACC,cAAc,GAAGC,4BAAY,CAACD,cAAc;AACxDD,uBAAW,CAACG,SAAS,GAAGC,QAAQ;AAChCJ,uBAAW,CAACK,SAAS,GAAGH,4BAAY,CAACG,SAAS;AAC9CL,uBAAW,CAACM,iBAAiB,GAAGJ,4BAAY,CAACI,iBAAiB;IAC9D,WAAeN,uBAAW"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var LC = require("lifecycle");
|
|
3
|
+
var BaseIterator = require("extract-base-iterator").default;
|
|
4
|
+
module.exports = LC.RefCountable.extend({
|
|
5
|
+
constructor: function constructor() {
|
|
6
|
+
LC.RefCountable.prototype.constructor.call(this);
|
|
7
|
+
},
|
|
8
|
+
__destroy: function __destroy() {
|
|
9
|
+
if (this.iterator) {
|
|
10
|
+
BaseIterator.prototype.end.call(this.iterator, this.err || null);
|
|
11
|
+
this.iterator = null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
17
|
+
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
18
|
+
for (var key in exports) exports.default[key] = exports[key];
|
|
19
|
+
module.exports = exports.default;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["Lock.cjs"],"sourcesContent":["const LC = require('lifecycle');\nconst BaseIterator = require('extract-base-iterator').default;\n\nmodule.exports = LC.RefCountable.extend({\n constructor: function () {\n LC.RefCountable.prototype.constructor.call(this);\n },\n __destroy: function () {\n if (this.iterator) {\n BaseIterator.prototype.end.call(this.iterator, this.err || null);\n this.iterator = null;\n }\n },\n});\n"],"names":["LC","require","BaseIterator","default","module","exports","RefCountable","extend","constructor","prototype","call","__destroy","iterator","end","err"],"mappings":";AAAA,IAAMA,KAAKC,QAAQ;AACnB,IAAMC,eAAeD,QAAQ,yBAAyBE,OAAO;AAE7DC,OAAOC,OAAO,GAAGL,GAAGM,YAAY,CAACC,MAAM,CAAC;IACtCC,aAAa,SAAbA;QACER,GAAGM,YAAY,CAACG,SAAS,CAACD,WAAW,CAACE,IAAI,CAAC,IAAI;IACjD;IACAC,WAAW,SAAXA;QACE,IAAI,IAAI,CAACC,QAAQ,EAAE;YACjBV,aAAaO,SAAS,CAACI,GAAG,CAACH,IAAI,CAAC,IAAI,CAACE,QAAQ,EAAE,IAAI,CAACE,GAAG,IAAI;YAC3D,IAAI,CAACF,QAAQ,GAAG;QAClB;IACF;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = function fifoRemove(fifo, value) {
|
|
3
|
+
for(var node = fifo.node; node; node = fifo.next(node)){
|
|
4
|
+
if (node.value === value) {
|
|
5
|
+
fifo.remove(node);
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return false;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
13
|
+
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
14
|
+
for (var key in exports) exports.default[key] = exports[key];
|
|
15
|
+
module.exports = exports.default;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["fifoRemove.cjs"],"sourcesContent":["module.exports = function fifoRemove(fifo, value) {\n for (let node = fifo.node; node; node = fifo.next(node)) {\n if (node.value === value) {\n fifo.remove(node);\n return true;\n }\n }\n return false;\n};\n"],"names":["module","exports","fifoRemove","fifo","value","node","next","remove"],"mappings":";AAAAA,OAAOC,OAAO,GAAG,SAASC,WAAWC,IAAI,EAAEC,KAAK;IAC9C,IAAK,IAAIC,OAAOF,KAAKE,IAAI,EAAEA,MAAMA,OAAOF,KAAKG,IAAI,CAACD,MAAO;QACvD,IAAIA,KAAKD,KAAK,KAAKA,OAAO;YACxBD,KAAKI,MAAM,CAACF;YACZ,OAAO;QACT;IACF;IACA,OAAO;AACT"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var access = require("fs-access-compat");
|
|
3
|
+
function waitForAccess(fullPath, callback) {
|
|
4
|
+
access(fullPath, function(err) {
|
|
5
|
+
if (err) return waitForAccess(fullPath, callback);
|
|
6
|
+
callback();
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
module.exports = waitForAccess;
|
|
10
|
+
|
|
11
|
+
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
12
|
+
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
13
|
+
for (var key in exports) exports.default[key] = exports[key];
|
|
14
|
+
module.exports = exports.default;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["waitForAccess.cjs"],"sourcesContent":["const access = require('fs-access-compat');\n\nfunction waitForAccess(fullPath, callback) {\n access(fullPath, (err) => {\n if (err) return waitForAccess(fullPath, callback);\n callback();\n });\n}\n\nmodule.exports = waitForAccess;\n"],"names":["access","require","waitForAccess","fullPath","callback","err","module","exports"],"mappings":";AAAA,IAAMA,SAASC,QAAQ;AAEvB,SAASC,cAAcC,QAAQ,EAAEC,QAAQ;IACvCJ,OAAOG,UAAU,SAACE;QAChB,IAAIA,KAAK,OAAOH,cAAcC,UAAUC;QACxCA;IACF;AACF;AAEAE,OAAOC,OAAO,GAAGL"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var once = require("once");
|
|
3
|
+
var path = require("path");
|
|
4
|
+
var compact = require("lodash.compact");
|
|
5
|
+
var assign = require("just-extend");
|
|
6
|
+
var BaseIterator = require("extract-base-iterator").default;
|
|
7
|
+
var DirectoryEntry = BaseIterator.DirectoryEntry;
|
|
8
|
+
var FileEntry = require("./FileEntry.js");
|
|
9
|
+
var LinkEntry = BaseIterator.LinkEntry;
|
|
10
|
+
var SymbolicLinkEntry = BaseIterator.SymbolicLinkEntry;
|
|
11
|
+
function nextEntry(next, iterator, callback) {
|
|
12
|
+
var extract = iterator.extract;
|
|
13
|
+
if (!extract) return callback(new Error("Extract missing"));
|
|
14
|
+
var _callback = callback;
|
|
15
|
+
callback = once(function callback(err, entry, next) {
|
|
16
|
+
extract.removeListener("entry", onEntry);
|
|
17
|
+
extract.removeListener("error", onError);
|
|
18
|
+
extract.removeListener("finish", onEnd);
|
|
19
|
+
// keep processing
|
|
20
|
+
if (entry) iterator.stack.push(nextEntry.bind(null, next));
|
|
21
|
+
// use null to indicate iteration is complete
|
|
22
|
+
_callback(err, err || !entry ? null : entry);
|
|
23
|
+
});
|
|
24
|
+
var onError = callback;
|
|
25
|
+
var onEnd = callback.bind(null, null);
|
|
26
|
+
var onEntry = function onEntry(header, stream, next) {
|
|
27
|
+
if (iterator.done) return callback(null, null, next);
|
|
28
|
+
var attributes = assign({}, header);
|
|
29
|
+
attributes.path = compact(header.name.split(path.sep)).join(path.sep);
|
|
30
|
+
attributes.mtime = new Date(attributes.mtime);
|
|
31
|
+
switch(attributes.type){
|
|
32
|
+
case "directory":
|
|
33
|
+
stream.resume(); // drain stream
|
|
34
|
+
return callback(null, new DirectoryEntry(attributes), next);
|
|
35
|
+
case "symlink":
|
|
36
|
+
stream.resume(); // drain stream
|
|
37
|
+
attributes.linkpath = header.linkname;
|
|
38
|
+
return callback(null, new SymbolicLinkEntry(attributes), next);
|
|
39
|
+
case "link":
|
|
40
|
+
stream.resume(); // drain stream
|
|
41
|
+
attributes.linkpath = header.linkname;
|
|
42
|
+
return callback(null, new LinkEntry(attributes), next);
|
|
43
|
+
case "file":
|
|
44
|
+
return callback(null, new FileEntry(attributes, stream, iterator.lock), next);
|
|
45
|
+
}
|
|
46
|
+
stream.resume(); // drain stream
|
|
47
|
+
return callback(new Error("Unrecognized entry type: ".concat(attributes.type)), null, next);
|
|
48
|
+
};
|
|
49
|
+
extract.on("entry", onEntry);
|
|
50
|
+
extract.on("error", onError);
|
|
51
|
+
extract.on("finish", onEnd);
|
|
52
|
+
if (next) next();
|
|
53
|
+
}
|
|
54
|
+
module.exports = nextEntry;
|
|
55
|
+
|
|
56
|
+
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
|
57
|
+
Object.defineProperty(exports.default, '__esModule', { value: true });
|
|
58
|
+
for (var key in exports) exports.default[key] = exports[key];
|
|
59
|
+
module.exports = exports.default;
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["nextEntry.cjs"],"sourcesContent":["const once = require('once');\nconst path = require('path');\nconst compact = require('lodash.compact');\nconst assign = require('just-extend');\n\nconst BaseIterator = require('extract-base-iterator').default;\nconst DirectoryEntry = BaseIterator.DirectoryEntry;\nconst FileEntry = require('./FileEntry.cjs');\nconst LinkEntry = BaseIterator.LinkEntry;\nconst SymbolicLinkEntry = BaseIterator.SymbolicLinkEntry;\n\nfunction nextEntry(next, iterator, callback) {\n const extract = iterator.extract;\n if (!extract) return callback(new Error('Extract missing'));\n\n const _callback = callback;\n callback = once(function callback(err, entry, next) {\n extract.removeListener('entry', onEntry);\n extract.removeListener('error', onError);\n extract.removeListener('finish', onEnd);\n\n // keep processing\n if (entry) iterator.stack.push(nextEntry.bind(null, next));\n\n // use null to indicate iteration is complete\n _callback(err, err || !entry ? null : entry);\n });\n\n const onError = callback;\n const onEnd = callback.bind(null, null);\n const onEntry = function onEntry(header, stream, next) {\n if (iterator.done) return callback(null, null, next);\n\n const attributes = assign({}, header);\n attributes.path = compact(header.name.split(path.sep)).join(path.sep);\n attributes.mtime = new Date(attributes.mtime);\n\n switch (attributes.type) {\n case 'directory':\n stream.resume(); // drain stream\n return callback(null, new DirectoryEntry(attributes), next);\n case 'symlink':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return callback(null, new SymbolicLinkEntry(attributes), next);\n case 'link':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return callback(null, new LinkEntry(attributes), next);\n case 'file':\n return callback(null, new FileEntry(attributes, stream, iterator.lock), next);\n }\n\n stream.resume(); // drain stream\n return callback(new Error(`Unrecognized entry type: ${attributes.type}`), null, next);\n };\n\n extract.on('entry', onEntry);\n extract.on('error', onError);\n extract.on('finish', onEnd);\n if (next) next();\n}\n\nmodule.exports = nextEntry;\n"],"names":["once","require","path","compact","assign","BaseIterator","default","DirectoryEntry","FileEntry","LinkEntry","SymbolicLinkEntry","nextEntry","next","iterator","callback","extract","Error","_callback","err","entry","removeListener","onEntry","onError","onEnd","stack","push","bind","header","stream","done","attributes","name","split","sep","join","mtime","Date","type","resume","linkpath","linkname","lock","on","module","exports"],"mappings":";AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,OAAOD,QAAQ;AACrB,IAAME,UAAUF,QAAQ;AACxB,IAAMG,SAASH,QAAQ;AAEvB,IAAMI,eAAeJ,QAAQ,yBAAyBK,OAAO;AAC7D,IAAMC,iBAAiBF,aAAaE,cAAc;AAClD,IAAMC,YAAYP,QAAQ;AAC1B,IAAMQ,YAAYJ,aAAaI,SAAS;AACxC,IAAMC,oBAAoBL,aAAaK,iBAAiB;AAExD,SAASC,UAAUC,IAAI,EAAEC,QAAQ,EAAEC,QAAQ;IACzC,IAAMC,UAAUF,SAASE,OAAO;IAChC,IAAI,CAACA,SAAS,OAAOD,SAAS,IAAIE,MAAM;IAExC,IAAMC,YAAYH;IAClBA,WAAWd,KAAK,SAASc,SAASI,GAAG,EAAEC,KAAK,EAAEP,IAAI;QAChDG,QAAQK,cAAc,CAAC,SAASC;QAChCN,QAAQK,cAAc,CAAC,SAASE;QAChCP,QAAQK,cAAc,CAAC,UAAUG;QAEjC,kBAAkB;QAClB,IAAIJ,OAAON,SAASW,KAAK,CAACC,IAAI,CAACd,UAAUe,IAAI,CAAC,MAAMd;QAEpD,6CAA6C;QAC7CK,UAAUC,KAAKA,OAAO,CAACC,QAAQ,OAAOA;IACxC;IAEA,IAAMG,UAAUR;IAChB,IAAMS,QAAQT,SAASY,IAAI,CAAC,MAAM;IAClC,IAAML,UAAU,SAASA,QAAQM,MAAM,EAAEC,MAAM,EAAEhB,IAAI;QACnD,IAAIC,SAASgB,IAAI,EAAE,OAAOf,SAAS,MAAM,MAAMF;QAE/C,IAAMkB,aAAa1B,OAAO,CAAC,GAAGuB;QAC9BG,WAAW5B,IAAI,GAAGC,QAAQwB,OAAOI,IAAI,CAACC,KAAK,CAAC9B,KAAK+B,GAAG,GAAGC,IAAI,CAAChC,KAAK+B,GAAG;QACpEH,WAAWK,KAAK,GAAG,IAAIC,KAAKN,WAAWK,KAAK;QAE5C,OAAQL,WAAWO,IAAI;YACrB,KAAK;gBACHT,OAAOU,MAAM,IAAI,eAAe;gBAChC,OAAOxB,SAAS,MAAM,IAAIP,eAAeuB,aAAalB;YACxD,KAAK;gBACHgB,OAAOU,MAAM,IAAI,eAAe;gBAChCR,WAAWS,QAAQ,GAAGZ,OAAOa,QAAQ;gBACrC,OAAO1B,SAAS,MAAM,IAAIJ,kBAAkBoB,aAAalB;YAC3D,KAAK;gBACHgB,OAAOU,MAAM,IAAI,eAAe;gBAChCR,WAAWS,QAAQ,GAAGZ,OAAOa,QAAQ;gBACrC,OAAO1B,SAAS,MAAM,IAAIL,UAAUqB,aAAalB;YACnD,KAAK;gBACH,OAAOE,SAAS,MAAM,IAAIN,UAAUsB,YAAYF,QAAQf,SAAS4B,IAAI,GAAG7B;QAC5E;QAEAgB,OAAOU,MAAM,IAAI,eAAe;QAChC,OAAOxB,SAAS,IAAIE,MAAM,AAAC,4BAA2C,OAAhBc,WAAWO,IAAI,IAAK,MAAMzB;IAClF;IAEAG,QAAQ2B,EAAE,CAAC,SAASrB;IACpBN,QAAQ2B,EAAE,CAAC,SAASpB;IACpBP,QAAQ2B,EAAE,CAAC,UAAUnB;IACrB,IAAIX,MAAMA;AACZ;AAEA+B,OAAOC,OAAO,GAAGjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export = FileEntry;
|
|
2
|
+
declare function FileEntry(attributes: any, stream: any, lock: any): void;
|
|
3
|
+
declare class FileEntry {
|
|
4
|
+
constructor(attributes: any, stream: any, lock: any);
|
|
5
|
+
stream: any;
|
|
6
|
+
lock: any;
|
|
7
|
+
create(dest: any, options: any, callback: any): any;
|
|
8
|
+
_writeFile(fullPath: any, _options: any, callback: any): any;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tar-iterator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Extract contents from tar archive type using an iterator API using streams or paths. Use stream interface and pipe transforms to add decompression algorithms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"extract",
|
|
@@ -38,24 +38,25 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"author": "Kevin Malakoff <kmalakoff@gmail.com> (https://github.com/kmalakoff)",
|
|
41
|
-
"main": "
|
|
41
|
+
"main": "dist/cjs/index.js",
|
|
42
|
+
"types": "dist/types/index.d.ts",
|
|
42
43
|
"files": [
|
|
43
|
-
"
|
|
44
|
+
"dist"
|
|
44
45
|
],
|
|
45
46
|
"scripts": {
|
|
46
|
-
"build": "",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"test": "
|
|
51
|
-
"
|
|
47
|
+
"build": "tsds build",
|
|
48
|
+
"deploy": "tsds deploy",
|
|
49
|
+
"format": "biome check --apply-unsafe src/ test/",
|
|
50
|
+
"test": "tsds test:node --timeout=10000",
|
|
51
|
+
"test:engines": "nvu engines npm test",
|
|
52
|
+
"version": "tsds version"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"end-of-stream": "^1.4.4",
|
|
55
|
-
"extract-base-iterator": "^0.
|
|
56
|
+
"extract-base-iterator": "^0.4.1",
|
|
56
57
|
"fs-access-compat": "^1.0.3",
|
|
57
58
|
"inherits": "^2.0.4",
|
|
58
|
-
"just-extend": "^6.
|
|
59
|
+
"just-extend": "^6.2.0",
|
|
59
60
|
"lifecycle": "^1.0.4",
|
|
60
61
|
"lodash.compact": "^3.0.1",
|
|
61
62
|
"mkpath": "^1.0.0",
|
|
@@ -65,22 +66,23 @@
|
|
|
65
66
|
"tar-stream-compat": "2.1.5"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
|
-
"@
|
|
69
|
+
"@biomejs/biome": "^1.5.3",
|
|
70
|
+
"@types/mocha": "^10.0.6",
|
|
71
|
+
"@types/node": "^20.11.19",
|
|
69
72
|
"cr": "^0.1.0",
|
|
70
|
-
"depcheck": "^1.4.
|
|
71
|
-
"
|
|
72
|
-
"eslint-config-prettier": "^8.5.0",
|
|
73
|
-
"eslint-config-standard": "^17.0.0",
|
|
74
|
-
"eslint-plugin-import": "^2.26.0",
|
|
75
|
-
"eslint-plugin-n": "^15.2.4",
|
|
76
|
-
"eslint-plugin-promise": "^6.0.0",
|
|
77
|
-
"fs-iterator": "^4.1.1",
|
|
73
|
+
"depcheck": "^1.4.7",
|
|
74
|
+
"fs-iterator": "^4.2.0",
|
|
78
75
|
"fs-stats-spys": "^1.0.2",
|
|
79
|
-
"
|
|
80
|
-
"prettier": "^2.7.1",
|
|
76
|
+
"ts-dev-stack": "^0.13.0",
|
|
81
77
|
"unbzip2-stream": "^1.4.3"
|
|
82
78
|
},
|
|
83
79
|
"engines": {
|
|
84
80
|
"node": ">=0.8"
|
|
81
|
+
},
|
|
82
|
+
"tsds": {
|
|
83
|
+
"source": "src/index.mjs",
|
|
84
|
+
"targets": [
|
|
85
|
+
"cjs"
|
|
86
|
+
]
|
|
85
87
|
}
|
|
86
88
|
}
|
package/lib/FileEntry.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
var inherits = require('inherits');
|
|
2
|
-
var BaseIterator = require('extract-base-iterator');
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
var eos = require('end-of-stream');
|
|
5
|
-
|
|
6
|
-
var waitForAccess = require('./lib/waitForAccess');
|
|
7
|
-
|
|
8
|
-
function FileEntry(attributes, stream, lock) {
|
|
9
|
-
BaseIterator.FileEntry.call(this, attributes);
|
|
10
|
-
this.stream = stream;
|
|
11
|
-
this.lock = lock;
|
|
12
|
-
this.lock.retain();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
inherits(FileEntry, BaseIterator.FileEntry);
|
|
16
|
-
|
|
17
|
-
FileEntry.prototype.create = function create(dest, options, callback) {
|
|
18
|
-
if (typeof options === 'function') {
|
|
19
|
-
callback = options;
|
|
20
|
-
options = null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var self = this;
|
|
24
|
-
if (typeof callback === 'function') {
|
|
25
|
-
options = options || {};
|
|
26
|
-
return BaseIterator.FileEntry.prototype.create.call(this, dest, options, function createCallback(err) {
|
|
27
|
-
callback(err);
|
|
28
|
-
if (self.lock) {
|
|
29
|
-
self.lock.release();
|
|
30
|
-
self.lock = null;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return new Promise(function createPromise(resolve, reject) {
|
|
36
|
-
self.create(dest, options, function createCallback(err, done) {
|
|
37
|
-
err ? reject(err) : resolve(done);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
FileEntry.prototype._writeFile = function _writeFile(fullPath, options, callback) {
|
|
43
|
-
if (!this.stream) return callback(new Error('Zip FileEntry missing stream. Check for calling create multiple times'));
|
|
44
|
-
|
|
45
|
-
var stream = this.stream;
|
|
46
|
-
this.stream = null;
|
|
47
|
-
var res = stream.pipe(fs.createWriteStream(fullPath));
|
|
48
|
-
eos(res, function (err) {
|
|
49
|
-
err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occassionally
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
FileEntry.prototype.destroy = function destroy() {
|
|
54
|
-
BaseIterator.FileEntry.prototype.destroy.call(this);
|
|
55
|
-
if (this.stream) {
|
|
56
|
-
this.stream.resume(); // drain stream
|
|
57
|
-
this.stream = null;
|
|
58
|
-
}
|
|
59
|
-
if (this.lock) {
|
|
60
|
-
this.lock.release();
|
|
61
|
-
this.lock = null;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
module.exports = FileEntry;
|
package/lib/TarIterator.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
var inherits = require('inherits');
|
|
2
|
-
var fs = require('fs');
|
|
3
|
-
var tarStream = require('tar-stream-compat');
|
|
4
|
-
var eos = require('end-of-stream');
|
|
5
|
-
var Queue = require('queue-cb');
|
|
6
|
-
var BaseIterator = require('extract-base-iterator');
|
|
7
|
-
|
|
8
|
-
var nextEntry = require('./nextEntry');
|
|
9
|
-
var fifoRemove = require('./lib/fifoRemove');
|
|
10
|
-
var Lock = require('./lib/Lock');
|
|
11
|
-
|
|
12
|
-
function TarIterator(source, options) {
|
|
13
|
-
if (!(this instanceof TarIterator)) return new TarIterator(source, options);
|
|
14
|
-
BaseIterator.call(this, options);
|
|
15
|
-
|
|
16
|
-
var self = this;
|
|
17
|
-
this.lock = new Lock();
|
|
18
|
-
this.lock.iterator = this;
|
|
19
|
-
|
|
20
|
-
var queue = Queue(1);
|
|
21
|
-
var cancelled = false;
|
|
22
|
-
function setup() {
|
|
23
|
-
cancelled = true;
|
|
24
|
-
}
|
|
25
|
-
this.processing.push(setup);
|
|
26
|
-
self.extract = tarStream.extract();
|
|
27
|
-
|
|
28
|
-
if (typeof source === 'string') source = fs.createReadStream(source);
|
|
29
|
-
queue.defer(function (callback) {
|
|
30
|
-
var data = null;
|
|
31
|
-
function cleanup() {
|
|
32
|
-
source.removeListener('error', onError);
|
|
33
|
-
source.removeListener('data', onData);
|
|
34
|
-
}
|
|
35
|
-
function onError(err) {
|
|
36
|
-
data = err;
|
|
37
|
-
cleanup();
|
|
38
|
-
callback(err);
|
|
39
|
-
}
|
|
40
|
-
function onData() {
|
|
41
|
-
data = true;
|
|
42
|
-
cleanup();
|
|
43
|
-
callback();
|
|
44
|
-
}
|
|
45
|
-
source.on('error', onError);
|
|
46
|
-
source.on('data', onData);
|
|
47
|
-
eos(source.pipe(self.extract), function (err) {
|
|
48
|
-
if (data) return;
|
|
49
|
-
cleanup();
|
|
50
|
-
callback(err);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// start processing
|
|
55
|
-
queue.await(function (err) {
|
|
56
|
-
fifoRemove(self.processing, setup);
|
|
57
|
-
if (self.done || cancelled) return; // done
|
|
58
|
-
err ? self.end(err) : self.push(nextEntry.bind(null, null));
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
inherits(TarIterator, BaseIterator);
|
|
63
|
-
|
|
64
|
-
TarIterator.prototype.end = function end(err) {
|
|
65
|
-
if (this.lock) {
|
|
66
|
-
this.lock.err = err;
|
|
67
|
-
this.lock.release();
|
|
68
|
-
this.lock = null;
|
|
69
|
-
} else {
|
|
70
|
-
BaseIterator.prototype.end.call(this, err); // call in lock release so end is properly handled
|
|
71
|
-
}
|
|
72
|
-
this.extract = null;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
module.exports = TarIterator;
|
package/lib/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
var BaseIterator = require('extract-base-iterator');
|
|
2
|
-
|
|
3
|
-
module.exports = require('./TarIterator');
|
|
4
|
-
module.exports.DirectoryEntry = BaseIterator.DirectoryEntry;
|
|
5
|
-
module.exports.FileEntry = require('./FileEntry');
|
|
6
|
-
module.exports.LinkEntry = BaseIterator.LinkEntry;
|
|
7
|
-
module.exports.SymbolicLinkEntry = BaseIterator.SymbolicLinkEntry;
|
package/lib/lib/Lock.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var LC = require('lifecycle');
|
|
2
|
-
var BaseIterator = require('extract-base-iterator');
|
|
3
|
-
|
|
4
|
-
module.exports = LC.RefCountable.extend({
|
|
5
|
-
constructor: function () {
|
|
6
|
-
LC.RefCountable.prototype.constructor.apply(this, arguments);
|
|
7
|
-
},
|
|
8
|
-
__destroy: function () {
|
|
9
|
-
if (this.iterator) {
|
|
10
|
-
BaseIterator.prototype.end.call(this.iterator, this.err || null);
|
|
11
|
-
this.iterator = null;
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
});
|
package/lib/lib/fifoRemove.js
DELETED
package/lib/lib/waitForAccess.js
DELETED
package/lib/nextEntry.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
var once = require('once');
|
|
2
|
-
var path = require('path');
|
|
3
|
-
var compact = require('lodash.compact');
|
|
4
|
-
var assign = require('just-extend');
|
|
5
|
-
|
|
6
|
-
var BaseIterator = require('extract-base-iterator');
|
|
7
|
-
var DirectoryEntry = BaseIterator.DirectoryEntry;
|
|
8
|
-
var FileEntry = require('./FileEntry');
|
|
9
|
-
var LinkEntry = BaseIterator.LinkEntry;
|
|
10
|
-
var SymbolicLinkEntry = BaseIterator.SymbolicLinkEntry;
|
|
11
|
-
|
|
12
|
-
function nextEntry(next, iterator, callback) {
|
|
13
|
-
var extract = iterator.extract;
|
|
14
|
-
if (!extract) return callback(new Error('Extract missing'));
|
|
15
|
-
|
|
16
|
-
var _callback = callback;
|
|
17
|
-
callback = once(function callback(err, entry, next) {
|
|
18
|
-
extract.removeListener('entry', onEntry);
|
|
19
|
-
extract.removeListener('error', onError);
|
|
20
|
-
extract.removeListener('finish', onEnd);
|
|
21
|
-
|
|
22
|
-
// keep processing
|
|
23
|
-
if (entry) iterator.stack.push(nextEntry.bind(null, next));
|
|
24
|
-
|
|
25
|
-
// use null to indicate iteration is complete
|
|
26
|
-
_callback(err, err || !entry ? null : entry);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
var onError = callback;
|
|
30
|
-
var onEnd = callback.bind(null, null);
|
|
31
|
-
var onEntry = function onEntry(header, stream, next) {
|
|
32
|
-
if (iterator.done) return callback(null, null, next);
|
|
33
|
-
|
|
34
|
-
var attributes = assign({}, header);
|
|
35
|
-
attributes.path = compact(header.name.split(path.sep)).join(path.sep);
|
|
36
|
-
attributes.mtime = new Date(attributes.mtime);
|
|
37
|
-
|
|
38
|
-
switch (attributes.type) {
|
|
39
|
-
case 'directory':
|
|
40
|
-
stream.resume(); // drain stream
|
|
41
|
-
return callback(null, new DirectoryEntry(attributes), next);
|
|
42
|
-
case 'symlink':
|
|
43
|
-
stream.resume(); // drain stream
|
|
44
|
-
attributes.linkpath = header.linkname;
|
|
45
|
-
return callback(null, new SymbolicLinkEntry(attributes), next);
|
|
46
|
-
case 'link':
|
|
47
|
-
stream.resume(); // drain stream
|
|
48
|
-
attributes.linkpath = header.linkname;
|
|
49
|
-
return callback(null, new LinkEntry(attributes), next);
|
|
50
|
-
case 'file':
|
|
51
|
-
return callback(null, new FileEntry(attributes, stream, iterator.lock), next);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
stream.resume(); // drain stream
|
|
55
|
-
return callback(new Error('Unrecognized entry type: ' + attributes.type), null, next);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
extract.on('entry', onEntry);
|
|
59
|
-
extract.on('error', onError);
|
|
60
|
-
extract.on('finish', onEnd);
|
|
61
|
-
if (next) next();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
module.exports = nextEntry;
|