tar-iterator 3.0.1 → 3.0.2
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/TarIterator.js +8 -6
- package/dist/cjs/TarIterator.js.map +1 -1
- package/dist/cjs/lib/Lock.d.cts +4 -0
- package/dist/cjs/lib/Lock.d.ts +4 -0
- package/dist/cjs/lib/Lock.js +14 -0
- package/dist/cjs/lib/Lock.js.map +1 -1
- package/dist/cjs/nextEntry.js +10 -1
- package/dist/cjs/nextEntry.js.map +1 -1
- package/dist/esm/TarIterator.js +8 -6
- package/dist/esm/TarIterator.js.map +1 -1
- package/dist/esm/lib/Lock.d.ts +4 -0
- package/dist/esm/lib/Lock.js +14 -0
- package/dist/esm/lib/Lock.js.map +1 -1
- package/dist/esm/nextEntry.js +10 -1
- package/dist/esm/nextEntry.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/TarIterator.js
CHANGED
|
@@ -99,12 +99,15 @@ var TarIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
99
99
|
// Note: options passed here are ExtractOptions (strip, force, etc.)
|
|
100
100
|
// TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different
|
|
101
101
|
_this.extract = new _TarExtractts.default();
|
|
102
|
+
_this.lock.extract = _this.extract;
|
|
102
103
|
var pipe = function(cb) {
|
|
103
104
|
try {
|
|
104
105
|
if (typeof source === 'string') source = _fs.default.createReadStream(source);
|
|
105
106
|
} catch (err) {
|
|
106
107
|
cb(err);
|
|
107
108
|
}
|
|
109
|
+
// Store source stream in lock for cleanup
|
|
110
|
+
_this.lock.sourceStream = source;
|
|
108
111
|
var end = (0, _calloncefn.default)(cb);
|
|
109
112
|
var self = _this;
|
|
110
113
|
source.on('data', function onData(chunk) {
|
|
@@ -132,12 +135,11 @@ var TarIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
132
135
|
}
|
|
133
136
|
var _proto = TarIterator.prototype;
|
|
134
137
|
_proto.end = function end(err) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
this.lock
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
_extractbaseiterator.default.prototype.end.call(this, err); // call in lock release so end is properly handled
|
|
138
|
+
var lock = this.lock;
|
|
139
|
+
if (lock) {
|
|
140
|
+
this.lock = null; // Clear FIRST to prevent re-entrancy
|
|
141
|
+
lock.err = err;
|
|
142
|
+
lock.release(); // Lock.__destroy() handles BaseIterator.end()
|
|
141
143
|
}
|
|
142
144
|
this.extract = null;
|
|
143
145
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/TarIterator.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport BaseIterator from 'extract-base-iterator';\nimport fs from 'fs';\n\nimport Lock from './lib/Lock.ts';\nimport nextEntry from './nextEntry.ts';\nimport TarExtract from './tar/TarExtract.ts';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarIterator extends BaseIterator {\n /** @internal @hidden */\n lock: Lock;\n /** @internal @hidden */\n extract: TarExtract;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.iterator = this;\n\n let cancelled = false;\n const setup = (): undefined => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Use our pure TarExtract instead of tar-stream-compat\n // Note: options passed here are ExtractOptions (strip, force, etc.)\n // TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different\n this.extract = new TarExtract();\n\n const pipe = (cb) => {\n try {\n if (typeof source === 'string') source = fs.createReadStream(source);\n } catch (err) {\n cb(err);\n }\n\n const end = once(cb);\n const self = this;\n (source as NodeJS.ReadableStream).on('data', function onData(chunk) {\n try {\n if (self.extract) self.extract.write(chunk);\n } catch (err) {\n // Handle synchronous errors from TarExtract (e.g., invalid format)\n end(err);\n }\n });\n (source as NodeJS.ReadableStream).on('data', function onFirstData() {\n end();\n });\n (source as NodeJS.ReadableStream).on('error', end);\n (source as NodeJS.ReadableStream).on('end', function onEnd() {\n if (self.extract) self.extract.end();\n });\n };\n pipe((err) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return; // done\n err ? this.end(err) : this.push(nextEntry.bind(null, null));\n });\n }\n\n end(err?: Error) {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/TarIterator.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport BaseIterator from 'extract-base-iterator';\nimport fs from 'fs';\n\nimport Lock from './lib/Lock.ts';\nimport nextEntry from './nextEntry.ts';\nimport TarExtract from './tar/TarExtract.ts';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarIterator extends BaseIterator {\n /** @internal @hidden */\n lock: Lock;\n /** @internal @hidden */\n extract: TarExtract;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.iterator = this;\n\n let cancelled = false;\n const setup = (): undefined => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Use our pure TarExtract instead of tar-stream-compat\n // Note: options passed here are ExtractOptions (strip, force, etc.)\n // TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different\n this.extract = new TarExtract();\n this.lock.extract = this.extract;\n\n const pipe = (cb) => {\n try {\n if (typeof source === 'string') source = fs.createReadStream(source);\n } catch (err) {\n cb(err);\n }\n\n // Store source stream in lock for cleanup\n this.lock.sourceStream = source as NodeJS.ReadableStream;\n\n const end = once(cb);\n const self = this;\n (source as NodeJS.ReadableStream).on('data', function onData(chunk) {\n try {\n if (self.extract) self.extract.write(chunk);\n } catch (err) {\n // Handle synchronous errors from TarExtract (e.g., invalid format)\n end(err);\n }\n });\n (source as NodeJS.ReadableStream).on('data', function onFirstData() {\n end();\n });\n (source as NodeJS.ReadableStream).on('error', end);\n (source as NodeJS.ReadableStream).on('end', function onEnd() {\n if (self.extract) self.extract.end();\n });\n };\n pipe((err) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return; // done\n err ? this.end(err) : this.push(nextEntry.bind(null, null));\n });\n }\n\n end(err?: Error) {\n const lock = this.lock;\n if (lock) {\n this.lock = null; // Clear FIRST to prevent re-entrancy\n lock.err = err;\n lock.release(); // Lock.__destroy() handles BaseIterator.end()\n }\n this.extract = null;\n }\n}\n"],"names":["TarIterator","source","options","lock","Lock","iterator","cancelled","setup","processing","push","extract","TarExtract","pipe","cb","fs","createReadStream","err","sourceStream","end","once","self","on","onData","chunk","write","onFirstData","onEnd","remove","done","nextEntry","bind","release","BaseIterator"],"mappings":";;;;;;;eAUqBA;;;iEAVJ;0EACQ;yDACV;6DAEE;kEACK;mEACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIR,IAAA,AAAMA,4BAAN;;cAAMA;aAAAA,YAMPC,MAAsC;YAAEC,UAAAA,iEAA0B,CAAC;gCAN5DF;;gBAOjB,kBAPiBA;YAOXE;;QACN,MAAKC,IAAI,GAAG,IAAIC,eAAI;QACpB,MAAKD,IAAI,CAACE,QAAQ;QAElB,IAAIC,YAAY;QAChB,IAAMC,QAAQ;YACZD,YAAY;QACd;QACA,MAAKE,UAAU,CAACC,IAAI,CAACF;QAErB,uDAAuD;QACvD,oEAAoE;QACpE,gFAAgF;QAChF,MAAKG,OAAO,GAAG,IAAIC,qBAAU;QAC7B,MAAKR,IAAI,CAACO,OAAO,GAAG,MAAKA,OAAO;QAEhC,IAAME,OAAO,SAACC;YACZ,IAAI;gBACF,IAAI,OAAOZ,WAAW,UAAUA,SAASa,WAAE,CAACC,gBAAgB,CAACd;YAC/D,EAAE,OAAOe,KAAK;gBACZH,GAAGG;YACL;YAEA,0CAA0C;YAC1C,MAAKb,IAAI,CAACc,YAAY,GAAGhB;YAEzB,IAAMiB,MAAMC,IAAAA,mBAAI,EAACN;YACjB,IAAMO;YACLnB,OAAiCoB,EAAE,CAAC,QAAQ,SAASC,OAAOC,KAAK;gBAChE,IAAI;oBACF,IAAIH,KAAKV,OAAO,EAAEU,KAAKV,OAAO,CAACc,KAAK,CAACD;gBACvC,EAAE,OAAOP,KAAK;oBACZ,mEAAmE;oBACnEE,IAAIF;gBACN;YACF;YACCf,OAAiCoB,EAAE,CAAC,QAAQ,SAASI;gBACpDP;YACF;YACCjB,OAAiCoB,EAAE,CAAC,SAASH;YAC7CjB,OAAiCoB,EAAE,CAAC,OAAO,SAASK;gBACnD,IAAIN,KAAKV,OAAO,EAAEU,KAAKV,OAAO,CAACQ,GAAG;YACpC;QACF;QACAN,KAAK,SAACI;YACJ,MAAKR,UAAU,CAACmB,MAAM,CAACpB;YACvB,IAAI,MAAKqB,IAAI,IAAItB,WAAW,QAAQ,OAAO;YAC3CU,MAAM,MAAKE,GAAG,CAACF,OAAO,MAAKP,IAAI,CAACoB,oBAAS,CAACC,IAAI,CAAC,MAAM;QACvD;;;iBAvDiB9B;IA0DnBkB,OAAAA,GAQC,GARDA,SAAAA,IAAIF,GAAW;QACb,IAAMb,OAAO,IAAI,CAACA,IAAI;QACtB,IAAIA,MAAM;YACR,IAAI,CAACA,IAAI,GAAG,MAAM,qCAAqC;YACvDA,KAAKa,GAAG,GAAGA;YACXb,KAAK4B,OAAO,IAAI,8CAA8C;QAChE;QACA,IAAI,CAACrB,OAAO,GAAG;IACjB;WAlEmBV;EAAoBgC,4BAAY"}
|
package/dist/cjs/lib/Lock.d.cts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import BaseIterator from 'extract-base-iterator';
|
|
2
|
+
import type TarExtract from '../tar/TarExtract.js';
|
|
2
3
|
export default class Lock {
|
|
3
4
|
private count;
|
|
4
5
|
iterator: BaseIterator;
|
|
5
6
|
err: Error;
|
|
7
|
+
/** @internal @hidden */
|
|
8
|
+
extract: TarExtract;
|
|
9
|
+
sourceStream: NodeJS.ReadableStream;
|
|
6
10
|
retain(): void;
|
|
7
11
|
release(): void;
|
|
8
12
|
private __destroy;
|
package/dist/cjs/lib/Lock.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import BaseIterator from 'extract-base-iterator';
|
|
2
|
+
import type TarExtract from '../tar/TarExtract.js';
|
|
2
3
|
export default class Lock {
|
|
3
4
|
private count;
|
|
4
5
|
iterator: BaseIterator;
|
|
5
6
|
err: Error;
|
|
7
|
+
/** @internal @hidden */
|
|
8
|
+
extract: TarExtract;
|
|
9
|
+
sourceStream: NodeJS.ReadableStream;
|
|
6
10
|
retain(): void;
|
|
7
11
|
release(): void;
|
|
8
12
|
private __destroy;
|
package/dist/cjs/lib/Lock.js
CHANGED
|
@@ -27,6 +27,9 @@ var Lock = /*#__PURE__*/ function() {
|
|
|
27
27
|
// members
|
|
28
28
|
this.iterator = null;
|
|
29
29
|
this.err = null;
|
|
30
|
+
// cleanup resources
|
|
31
|
+
/** @internal @hidden */ this.extract = null;
|
|
32
|
+
this.sourceStream = null;
|
|
30
33
|
}
|
|
31
34
|
var _proto = Lock.prototype;
|
|
32
35
|
_proto.retain = function retain() {
|
|
@@ -38,6 +41,17 @@ var Lock = /*#__PURE__*/ function() {
|
|
|
38
41
|
if (this.count === 0) this.__destroy();
|
|
39
42
|
};
|
|
40
43
|
_proto.__destroy = function __destroy() {
|
|
44
|
+
// Destroy source stream FIRST to stop data flow
|
|
45
|
+
if (this.sourceStream) {
|
|
46
|
+
var stream = this.sourceStream;
|
|
47
|
+
if (typeof stream.destroy === 'function') stream.destroy();
|
|
48
|
+
this.sourceStream = null;
|
|
49
|
+
}
|
|
50
|
+
// Clear extract reference
|
|
51
|
+
if (this.extract) {
|
|
52
|
+
this.extract = null;
|
|
53
|
+
}
|
|
54
|
+
// Call BaseIterator.end() LAST
|
|
41
55
|
if (this.iterator) {
|
|
42
56
|
_extractbaseiterator.default.prototype.end.call(this.iterator, this.err || null);
|
|
43
57
|
this.iterator = null;
|
package/dist/cjs/lib/Lock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/lib/Lock.ts"],"sourcesContent":["import BaseIterator from 'extract-base-iterator';\n\nexport default class Lock {\n private count = 1;\n\n // members\n iterator: BaseIterator = null;\n err: Error = null;\n\n retain() {\n this.count++;\n }\n\n release() {\n if (this.count <= 0) throw new Error('Lock count is corrupted');\n this.count--;\n if (this.count === 0) this.__destroy();\n }\n\n private __destroy() {\n if (this.iterator) {\n BaseIterator.prototype.end.call(this.iterator, this.err || null);\n this.iterator = null;\n }\n }\n}\n"],"names":["Lock","count","iterator","err","retain","release","Error","__destroy","BaseIterator","prototype","end","call"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/lib/Lock.ts"],"sourcesContent":["import BaseIterator from 'extract-base-iterator';\nimport type TarExtract from '../tar/TarExtract.ts';\n\nexport default class Lock {\n private count = 1;\n\n // members\n iterator: BaseIterator = null;\n err: Error = null;\n\n // cleanup resources\n /** @internal @hidden */\n extract: TarExtract = null;\n sourceStream: NodeJS.ReadableStream = null;\n\n retain() {\n this.count++;\n }\n\n release() {\n if (this.count <= 0) throw new Error('Lock count is corrupted');\n this.count--;\n if (this.count === 0) this.__destroy();\n }\n\n private __destroy() {\n // Destroy source stream FIRST to stop data flow\n if (this.sourceStream) {\n const stream = this.sourceStream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof stream.destroy === 'function') stream.destroy();\n this.sourceStream = null;\n }\n\n // Clear extract reference\n if (this.extract) {\n this.extract = null;\n }\n\n // Call BaseIterator.end() LAST\n if (this.iterator) {\n BaseIterator.prototype.end.call(this.iterator, this.err || null);\n this.iterator = null;\n }\n }\n}\n"],"names":["Lock","count","iterator","err","extract","sourceStream","retain","release","Error","__destroy","stream","destroy","BaseIterator","prototype","end","call"],"mappings":";;;;;;;eAGqBA;;;0EAHI;;;;;;;;;;;AAGV,IAAA,AAAMA,qBAAN;;aAAMA;gCAAAA;aACXC,QAAQ;QAEhB,UAAU;aACVC,WAAyB;aACzBC,MAAa;QAEb,oBAAoB;QACpB,sBAAsB,QACtBC,UAAsB;aACtBC,eAAsC;;iBAVnBL;IAYnBM,OAAAA,MAEC,GAFDA,SAAAA;QACE,IAAI,CAACL,KAAK;IACZ;IAEAM,OAAAA,OAIC,GAJDA,SAAAA;QACE,IAAI,IAAI,CAACN,KAAK,IAAI,GAAG,MAAM,IAAIO,MAAM;QACrC,IAAI,CAACP,KAAK;QACV,IAAI,IAAI,CAACA,KAAK,KAAK,GAAG,IAAI,CAACQ,SAAS;IACtC;IAEA,OAAQA,SAkBP,GAlBD,SAAQA;QACN,gDAAgD;QAChD,IAAI,IAAI,CAACJ,YAAY,EAAE;YACrB,IAAMK,SAAS,IAAI,CAACL,YAAY;YAChC,IAAI,OAAOK,OAAOC,OAAO,KAAK,YAAYD,OAAOC,OAAO;YACxD,IAAI,CAACN,YAAY,GAAG;QACtB;QAEA,0BAA0B;QAC1B,IAAI,IAAI,CAACD,OAAO,EAAE;YAChB,IAAI,CAACA,OAAO,GAAG;QACjB;QAEA,+BAA+B;QAC/B,IAAI,IAAI,CAACF,QAAQ,EAAE;YACjBU,4BAAY,CAACC,SAAS,CAACC,GAAG,CAACC,IAAI,CAAC,IAAI,CAACb,QAAQ,EAAE,IAAI,CAACC,GAAG,IAAI;YAC3D,IAAI,CAACD,QAAQ,GAAG;QAClB;IACF;WAxCmBF"}
|
package/dist/cjs/nextEntry.js
CHANGED
|
@@ -50,6 +50,13 @@ var _setImmediate = typeof setImmediate === 'function' ? setImmediate : typeof p
|
|
|
50
50
|
setTimeout(fn, 0);
|
|
51
51
|
};
|
|
52
52
|
function nextEntry(next, iterator, callback) {
|
|
53
|
+
// Guard: bail early if iterator already ended
|
|
54
|
+
if (!iterator.lock || iterator.isDone()) {
|
|
55
|
+
return callback(null, {
|
|
56
|
+
done: true,
|
|
57
|
+
value: null
|
|
58
|
+
});
|
|
59
|
+
}
|
|
53
60
|
var extract = iterator.extract;
|
|
54
61
|
if (!extract) return callback(new Error('Extract missing'));
|
|
55
62
|
var nextCallback = (0, _calloncefn.default)(function(err, entry, next) {
|
|
@@ -73,7 +80,9 @@ function nextEntry(next, iterator, callback) {
|
|
|
73
80
|
var onError = callback;
|
|
74
81
|
var onEnd = callback.bind(null, null);
|
|
75
82
|
var onEntry = function onEntry(header, stream, next) {
|
|
76
|
-
if
|
|
83
|
+
// Guard: skip if iterator already ended (stale lock)
|
|
84
|
+
if (!iterator.lock || iterator.isDone()) {
|
|
85
|
+
stream.resume(); // drain stream
|
|
77
86
|
return nextCallback(null, null, next);
|
|
78
87
|
}
|
|
79
88
|
var attributes = _object_spread({}, header);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/nextEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';\nimport path from 'path';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\n// Node 0.8 compatible setImmediate (setImmediate was added in Node 0.10)\nconst _setImmediate =\n typeof setImmediate === 'function'\n ? setImmediate\n : typeof process !== 'undefined' && typeof process.nextTick === 'function'\n ? process.nextTick\n : function setImmediateFallback(fn: () => void) {\n setTimeout(fn, 0);\n };\n\nexport type TarNext = () => undefined;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => undefined;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): undefined {\n const extract = iterator.extract;\n if (!extract) return callback(new Error('Extract missing'));\n\n const nextCallback = once((err?: Error, entry?: Entry, next?: TarNext) => {\n extract.removeListener('entry', onEntry);\n extract.removeListener('error', onError);\n extract.removeListener('finish', onEnd);\n\n // keep processing\n if (entry) iterator.push(nextEntry.bind(null, next));\n\n // Use setImmediate to defer the callback invocation\n // This ensures proper async behavior with the BaseIterator\n _setImmediate(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n });\n }) as NextCallback;\n\n const onError = callback;\n const onEnd = callback.bind(null, null);\n const onEntry = function onEntry(header, stream, next: TarNext) {\n if (iterator.isDone()) {\n return nextCallback(null, null, next);\n }\n\n const attributes = { ...header };\n attributes.path = header.name.split(path.sep).filter(Boolean).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 nextCallback(null, new DirectoryEntry(attributes), next);\n case 'symlink':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new SymbolicLinkEntry(attributes), next);\n case 'link':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new LinkEntry(attributes), next);\n case 'file':\n return nextCallback(null, new FileEntry(attributes, stream, iterator.lock), next);\n }\n\n stream.resume(); // drain stream\n return nextCallback(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\n // Resume parsing to emit any pending entry\n // For first call (next is null), this triggers the first entry emission\n // For subsequent calls, next() unlocks the parser which then processes the next header\n if (next) {\n next();\n } else {\n // First call - resume to emit any pending entry\n extract.resume();\n }\n}\n"],"names":["nextEntry","_setImmediate","setImmediate","process","nextTick","setImmediateFallback","fn","setTimeout","next","iterator","callback","extract","Error","nextCallback","once","err","entry","removeListener","onEntry","onError","onEnd","push","bind","
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/nextEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';\nimport path from 'path';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\n// Node 0.8 compatible setImmediate (setImmediate was added in Node 0.10)\nconst _setImmediate =\n typeof setImmediate === 'function'\n ? setImmediate\n : typeof process !== 'undefined' && typeof process.nextTick === 'function'\n ? process.nextTick\n : function setImmediateFallback(fn: () => void) {\n setTimeout(fn, 0);\n };\n\nexport type TarNext = () => undefined;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => undefined;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): undefined {\n // Guard: bail early if iterator already ended\n if (!iterator.lock || iterator.isDone()) {\n return callback(null, { done: true, value: null });\n }\n\n const extract = iterator.extract;\n if (!extract) return callback(new Error('Extract missing'));\n\n const nextCallback = once((err?: Error, entry?: Entry, next?: TarNext) => {\n extract.removeListener('entry', onEntry);\n extract.removeListener('error', onError);\n extract.removeListener('finish', onEnd);\n\n // keep processing\n if (entry) iterator.push(nextEntry.bind(null, next));\n\n // Use setImmediate to defer the callback invocation\n // This ensures proper async behavior with the BaseIterator\n _setImmediate(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n });\n }) as NextCallback;\n\n const onError = callback;\n const onEnd = callback.bind(null, null);\n const onEntry = function onEntry(header, stream, next: TarNext) {\n // Guard: skip if iterator already ended (stale lock)\n if (!iterator.lock || iterator.isDone()) {\n stream.resume(); // drain stream\n return nextCallback(null, null, next);\n }\n\n const attributes = { ...header };\n attributes.path = header.name.split(path.sep).filter(Boolean).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 nextCallback(null, new DirectoryEntry(attributes), next);\n case 'symlink':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new SymbolicLinkEntry(attributes), next);\n case 'link':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new LinkEntry(attributes), next);\n case 'file':\n return nextCallback(null, new FileEntry(attributes, stream, iterator.lock), next);\n }\n\n stream.resume(); // drain stream\n return nextCallback(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\n // Resume parsing to emit any pending entry\n // For first call (next is null), this triggers the first entry emission\n // For subsequent calls, next() unlocks the parser which then processes the next header\n if (next) {\n next();\n } else {\n // First call - resume to emit any pending entry\n extract.resume();\n }\n}\n"],"names":["nextEntry","_setImmediate","setImmediate","process","nextTick","setImmediateFallback","fn","setTimeout","next","iterator","callback","lock","isDone","done","value","extract","Error","nextCallback","once","err","entry","removeListener","onEntry","onError","onEnd","push","bind","header","stream","resume","attributes","path","name","split","sep","filter","Boolean","join","mtime","Date","type","DirectoryEntry","linkpath","linkname","SymbolicLinkEntry","LinkEntry","FileEntry","on"],"mappings":"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"}
|
package/dist/esm/TarIterator.js
CHANGED
|
@@ -6,12 +6,11 @@ import nextEntry from './nextEntry.js';
|
|
|
6
6
|
import TarExtract from './tar/TarExtract.js';
|
|
7
7
|
let TarIterator = class TarIterator extends BaseIterator {
|
|
8
8
|
end(err) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.lock
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
BaseIterator.prototype.end.call(this, err); // call in lock release so end is properly handled
|
|
9
|
+
const lock = this.lock;
|
|
10
|
+
if (lock) {
|
|
11
|
+
this.lock = null; // Clear FIRST to prevent re-entrancy
|
|
12
|
+
lock.err = err;
|
|
13
|
+
lock.release(); // Lock.__destroy() handles BaseIterator.end()
|
|
15
14
|
}
|
|
16
15
|
this.extract = null;
|
|
17
16
|
}
|
|
@@ -28,12 +27,15 @@ let TarIterator = class TarIterator extends BaseIterator {
|
|
|
28
27
|
// Note: options passed here are ExtractOptions (strip, force, etc.)
|
|
29
28
|
// TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different
|
|
30
29
|
this.extract = new TarExtract();
|
|
30
|
+
this.lock.extract = this.extract;
|
|
31
31
|
const pipe = (cb)=>{
|
|
32
32
|
try {
|
|
33
33
|
if (typeof source === 'string') source = fs.createReadStream(source);
|
|
34
34
|
} catch (err) {
|
|
35
35
|
cb(err);
|
|
36
36
|
}
|
|
37
|
+
// Store source stream in lock for cleanup
|
|
38
|
+
this.lock.sourceStream = source;
|
|
37
39
|
const end = once(cb);
|
|
38
40
|
const self = this;
|
|
39
41
|
source.on('data', function onData(chunk) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/TarIterator.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport BaseIterator from 'extract-base-iterator';\nimport fs from 'fs';\n\nimport Lock from './lib/Lock.ts';\nimport nextEntry from './nextEntry.ts';\nimport TarExtract from './tar/TarExtract.ts';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarIterator extends BaseIterator {\n /** @internal @hidden */\n lock: Lock;\n /** @internal @hidden */\n extract: TarExtract;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.iterator = this;\n\n let cancelled = false;\n const setup = (): undefined => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Use our pure TarExtract instead of tar-stream-compat\n // Note: options passed here are ExtractOptions (strip, force, etc.)\n // TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different\n this.extract = new TarExtract();\n\n const pipe = (cb) => {\n try {\n if (typeof source === 'string') source = fs.createReadStream(source);\n } catch (err) {\n cb(err);\n }\n\n const end = once(cb);\n const self = this;\n (source as NodeJS.ReadableStream).on('data', function onData(chunk) {\n try {\n if (self.extract) self.extract.write(chunk);\n } catch (err) {\n // Handle synchronous errors from TarExtract (e.g., invalid format)\n end(err);\n }\n });\n (source as NodeJS.ReadableStream).on('data', function onFirstData() {\n end();\n });\n (source as NodeJS.ReadableStream).on('error', end);\n (source as NodeJS.ReadableStream).on('end', function onEnd() {\n if (self.extract) self.extract.end();\n });\n };\n pipe((err) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return; // done\n err ? this.end(err) : this.push(nextEntry.bind(null, null));\n });\n }\n\n end(err?: Error) {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/TarIterator.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport BaseIterator from 'extract-base-iterator';\nimport fs from 'fs';\n\nimport Lock from './lib/Lock.ts';\nimport nextEntry from './nextEntry.ts';\nimport TarExtract from './tar/TarExtract.ts';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarIterator extends BaseIterator {\n /** @internal @hidden */\n lock: Lock;\n /** @internal @hidden */\n extract: TarExtract;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.iterator = this;\n\n let cancelled = false;\n const setup = (): undefined => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Use our pure TarExtract instead of tar-stream-compat\n // Note: options passed here are ExtractOptions (strip, force, etc.)\n // TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different\n this.extract = new TarExtract();\n this.lock.extract = this.extract;\n\n const pipe = (cb) => {\n try {\n if (typeof source === 'string') source = fs.createReadStream(source);\n } catch (err) {\n cb(err);\n }\n\n // Store source stream in lock for cleanup\n this.lock.sourceStream = source as NodeJS.ReadableStream;\n\n const end = once(cb);\n const self = this;\n (source as NodeJS.ReadableStream).on('data', function onData(chunk) {\n try {\n if (self.extract) self.extract.write(chunk);\n } catch (err) {\n // Handle synchronous errors from TarExtract (e.g., invalid format)\n end(err);\n }\n });\n (source as NodeJS.ReadableStream).on('data', function onFirstData() {\n end();\n });\n (source as NodeJS.ReadableStream).on('error', end);\n (source as NodeJS.ReadableStream).on('end', function onEnd() {\n if (self.extract) self.extract.end();\n });\n };\n pipe((err) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return; // done\n err ? this.end(err) : this.push(nextEntry.bind(null, null));\n });\n }\n\n end(err?: Error) {\n const lock = this.lock;\n if (lock) {\n this.lock = null; // Clear FIRST to prevent re-entrancy\n lock.err = err;\n lock.release(); // Lock.__destroy() handles BaseIterator.end()\n }\n this.extract = null;\n }\n}\n"],"names":["once","BaseIterator","fs","Lock","nextEntry","TarExtract","TarIterator","end","err","lock","release","extract","source","options","iterator","cancelled","setup","processing","push","pipe","cb","createReadStream","sourceStream","self","on","onData","chunk","write","onFirstData","onEnd","remove","done","bind"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,OAAOC,kBAAkB,wBAAwB;AACjD,OAAOC,QAAQ,KAAK;AAEpB,OAAOC,UAAU,gBAAgB;AACjC,OAAOC,eAAe,iBAAiB;AACvC,OAAOC,gBAAgB,sBAAsB;AAI9B,IAAA,AAAMC,cAAN,MAAMA,oBAAoBL;IA0DvCM,IAAIC,GAAW,EAAE;QACf,MAAMC,OAAO,IAAI,CAACA,IAAI;QACtB,IAAIA,MAAM;YACR,IAAI,CAACA,IAAI,GAAG,MAAM,qCAAqC;YACvDA,KAAKD,GAAG,GAAGA;YACXC,KAAKC,OAAO,IAAI,8CAA8C;QAChE;QACA,IAAI,CAACC,OAAO,GAAG;IACjB;IA5DA,YAAYC,MAAsC,EAAEC,UAA0B,CAAC,CAAC,CAAE;QAChF,KAAK,CAACA;QACN,IAAI,CAACJ,IAAI,GAAG,IAAIN;QAChB,IAAI,CAACM,IAAI,CAACK,QAAQ,GAAG,IAAI;QAEzB,IAAIC,YAAY;QAChB,MAAMC,QAAQ;YACZD,YAAY;QACd;QACA,IAAI,CAACE,UAAU,CAACC,IAAI,CAACF;QAErB,uDAAuD;QACvD,oEAAoE;QACpE,gFAAgF;QAChF,IAAI,CAACL,OAAO,GAAG,IAAIN;QACnB,IAAI,CAACI,IAAI,CAACE,OAAO,GAAG,IAAI,CAACA,OAAO;QAEhC,MAAMQ,OAAO,CAACC;YACZ,IAAI;gBACF,IAAI,OAAOR,WAAW,UAAUA,SAASV,GAAGmB,gBAAgB,CAACT;YAC/D,EAAE,OAAOJ,KAAK;gBACZY,GAAGZ;YACL;YAEA,0CAA0C;YAC1C,IAAI,CAACC,IAAI,CAACa,YAAY,GAAGV;YAEzB,MAAML,MAAMP,KAAKoB;YACjB,MAAMG,OAAO,IAAI;YAChBX,OAAiCY,EAAE,CAAC,QAAQ,SAASC,OAAOC,KAAK;gBAChE,IAAI;oBACF,IAAIH,KAAKZ,OAAO,EAAEY,KAAKZ,OAAO,CAACgB,KAAK,CAACD;gBACvC,EAAE,OAAOlB,KAAK;oBACZ,mEAAmE;oBACnED,IAAIC;gBACN;YACF;YACCI,OAAiCY,EAAE,CAAC,QAAQ,SAASI;gBACpDrB;YACF;YACCK,OAAiCY,EAAE,CAAC,SAASjB;YAC7CK,OAAiCY,EAAE,CAAC,OAAO,SAASK;gBACnD,IAAIN,KAAKZ,OAAO,EAAEY,KAAKZ,OAAO,CAACJ,GAAG;YACpC;QACF;QACAY,KAAK,CAACX;YACJ,IAAI,CAACS,UAAU,CAACa,MAAM,CAACd;YACvB,IAAI,IAAI,CAACe,IAAI,IAAIhB,WAAW,QAAQ,OAAO;YAC3CP,MAAM,IAAI,CAACD,GAAG,CAACC,OAAO,IAAI,CAACU,IAAI,CAACd,UAAU4B,IAAI,CAAC,MAAM;QACvD;IACF;AAWF;AAnEA,SAAqB1B,yBAmEpB"}
|
package/dist/esm/lib/Lock.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import BaseIterator from 'extract-base-iterator';
|
|
2
|
+
import type TarExtract from '../tar/TarExtract.js';
|
|
2
3
|
export default class Lock {
|
|
3
4
|
private count;
|
|
4
5
|
iterator: BaseIterator;
|
|
5
6
|
err: Error;
|
|
7
|
+
/** @internal @hidden */
|
|
8
|
+
extract: TarExtract;
|
|
9
|
+
sourceStream: NodeJS.ReadableStream;
|
|
6
10
|
retain(): void;
|
|
7
11
|
release(): void;
|
|
8
12
|
private __destroy;
|
package/dist/esm/lib/Lock.js
CHANGED
|
@@ -9,6 +9,17 @@ let Lock = class Lock {
|
|
|
9
9
|
if (this.count === 0) this.__destroy();
|
|
10
10
|
}
|
|
11
11
|
__destroy() {
|
|
12
|
+
// Destroy source stream FIRST to stop data flow
|
|
13
|
+
if (this.sourceStream) {
|
|
14
|
+
const stream = this.sourceStream;
|
|
15
|
+
if (typeof stream.destroy === 'function') stream.destroy();
|
|
16
|
+
this.sourceStream = null;
|
|
17
|
+
}
|
|
18
|
+
// Clear extract reference
|
|
19
|
+
if (this.extract) {
|
|
20
|
+
this.extract = null;
|
|
21
|
+
}
|
|
22
|
+
// Call BaseIterator.end() LAST
|
|
12
23
|
if (this.iterator) {
|
|
13
24
|
BaseIterator.prototype.end.call(this.iterator, this.err || null);
|
|
14
25
|
this.iterator = null;
|
|
@@ -19,6 +30,9 @@ let Lock = class Lock {
|
|
|
19
30
|
// members
|
|
20
31
|
this.iterator = null;
|
|
21
32
|
this.err = null;
|
|
33
|
+
// cleanup resources
|
|
34
|
+
/** @internal @hidden */ this.extract = null;
|
|
35
|
+
this.sourceStream = null;
|
|
22
36
|
}
|
|
23
37
|
};
|
|
24
38
|
export { Lock as default };
|
package/dist/esm/lib/Lock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/lib/Lock.ts"],"sourcesContent":["import BaseIterator from 'extract-base-iterator';\n\nexport default class Lock {\n private count = 1;\n\n // members\n iterator: BaseIterator = null;\n err: Error = null;\n\n retain() {\n this.count++;\n }\n\n release() {\n if (this.count <= 0) throw new Error('Lock count is corrupted');\n this.count--;\n if (this.count === 0) this.__destroy();\n }\n\n private __destroy() {\n if (this.iterator) {\n BaseIterator.prototype.end.call(this.iterator, this.err || null);\n this.iterator = null;\n }\n }\n}\n"],"names":["BaseIterator","Lock","retain","count","release","Error","__destroy","iterator","prototype","end","call","err"],"mappings":"AAAA,OAAOA,kBAAkB,wBAAwB;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/lib/Lock.ts"],"sourcesContent":["import BaseIterator from 'extract-base-iterator';\nimport type TarExtract from '../tar/TarExtract.ts';\n\nexport default class Lock {\n private count = 1;\n\n // members\n iterator: BaseIterator = null;\n err: Error = null;\n\n // cleanup resources\n /** @internal @hidden */\n extract: TarExtract = null;\n sourceStream: NodeJS.ReadableStream = null;\n\n retain() {\n this.count++;\n }\n\n release() {\n if (this.count <= 0) throw new Error('Lock count is corrupted');\n this.count--;\n if (this.count === 0) this.__destroy();\n }\n\n private __destroy() {\n // Destroy source stream FIRST to stop data flow\n if (this.sourceStream) {\n const stream = this.sourceStream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof stream.destroy === 'function') stream.destroy();\n this.sourceStream = null;\n }\n\n // Clear extract reference\n if (this.extract) {\n this.extract = null;\n }\n\n // Call BaseIterator.end() LAST\n if (this.iterator) {\n BaseIterator.prototype.end.call(this.iterator, this.err || null);\n this.iterator = null;\n }\n }\n}\n"],"names":["BaseIterator","Lock","retain","count","release","Error","__destroy","sourceStream","stream","destroy","extract","iterator","prototype","end","call","err"],"mappings":"AAAA,OAAOA,kBAAkB,wBAAwB;AAGlC,IAAA,AAAMC,OAAN,MAAMA;IAYnBC,SAAS;QACP,IAAI,CAACC,KAAK;IACZ;IAEAC,UAAU;QACR,IAAI,IAAI,CAACD,KAAK,IAAI,GAAG,MAAM,IAAIE,MAAM;QACrC,IAAI,CAACF,KAAK;QACV,IAAI,IAAI,CAACA,KAAK,KAAK,GAAG,IAAI,CAACG,SAAS;IACtC;IAEQA,YAAY;QAClB,gDAAgD;QAChD,IAAI,IAAI,CAACC,YAAY,EAAE;YACrB,MAAMC,SAAS,IAAI,CAACD,YAAY;YAChC,IAAI,OAAOC,OAAOC,OAAO,KAAK,YAAYD,OAAOC,OAAO;YACxD,IAAI,CAACF,YAAY,GAAG;QACtB;QAEA,0BAA0B;QAC1B,IAAI,IAAI,CAACG,OAAO,EAAE;YAChB,IAAI,CAACA,OAAO,GAAG;QACjB;QAEA,+BAA+B;QAC/B,IAAI,IAAI,CAACC,QAAQ,EAAE;YACjBX,aAAaY,SAAS,CAACC,GAAG,CAACC,IAAI,CAAC,IAAI,CAACH,QAAQ,EAAE,IAAI,CAACI,GAAG,IAAI;YAC3D,IAAI,CAACJ,QAAQ,GAAG;QAClB;IACF;;aAvCQR,QAAQ;QAEhB,UAAU;aACVQ,WAAyB;aACzBI,MAAa;QAEb,oBAAoB;QACpB,sBAAsB,QACtBL,UAAsB;aACtBH,eAAsC;;AA+BxC;AAzCA,SAAqBN,kBAyCpB"}
|
package/dist/esm/nextEntry.js
CHANGED
|
@@ -7,6 +7,13 @@ const _setImmediate = typeof setImmediate === 'function' ? setImmediate : typeof
|
|
|
7
7
|
setTimeout(fn, 0);
|
|
8
8
|
};
|
|
9
9
|
export default function nextEntry(next, iterator, callback) {
|
|
10
|
+
// Guard: bail early if iterator already ended
|
|
11
|
+
if (!iterator.lock || iterator.isDone()) {
|
|
12
|
+
return callback(null, {
|
|
13
|
+
done: true,
|
|
14
|
+
value: null
|
|
15
|
+
});
|
|
16
|
+
}
|
|
10
17
|
const extract = iterator.extract;
|
|
11
18
|
if (!extract) return callback(new Error('Extract missing'));
|
|
12
19
|
const nextCallback = once((err, entry, next)=>{
|
|
@@ -30,7 +37,9 @@ export default function nextEntry(next, iterator, callback) {
|
|
|
30
37
|
const onError = callback;
|
|
31
38
|
const onEnd = callback.bind(null, null);
|
|
32
39
|
const onEntry = function onEntry(header, stream, next) {
|
|
33
|
-
if
|
|
40
|
+
// Guard: skip if iterator already ended (stale lock)
|
|
41
|
+
if (!iterator.lock || iterator.isDone()) {
|
|
42
|
+
stream.resume(); // drain stream
|
|
34
43
|
return nextCallback(null, null, next);
|
|
35
44
|
}
|
|
36
45
|
const attributes = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/nextEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';\nimport path from 'path';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\n// Node 0.8 compatible setImmediate (setImmediate was added in Node 0.10)\nconst _setImmediate =\n typeof setImmediate === 'function'\n ? setImmediate\n : typeof process !== 'undefined' && typeof process.nextTick === 'function'\n ? process.nextTick\n : function setImmediateFallback(fn: () => void) {\n setTimeout(fn, 0);\n };\n\nexport type TarNext = () => undefined;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => undefined;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): undefined {\n const extract = iterator.extract;\n if (!extract) return callback(new Error('Extract missing'));\n\n const nextCallback = once((err?: Error, entry?: Entry, next?: TarNext) => {\n extract.removeListener('entry', onEntry);\n extract.removeListener('error', onError);\n extract.removeListener('finish', onEnd);\n\n // keep processing\n if (entry) iterator.push(nextEntry.bind(null, next));\n\n // Use setImmediate to defer the callback invocation\n // This ensures proper async behavior with the BaseIterator\n _setImmediate(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n });\n }) as NextCallback;\n\n const onError = callback;\n const onEnd = callback.bind(null, null);\n const onEntry = function onEntry(header, stream, next: TarNext) {\n if (iterator.isDone()) {\n return nextCallback(null, null, next);\n }\n\n const attributes = { ...header };\n attributes.path = header.name.split(path.sep).filter(Boolean).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 nextCallback(null, new DirectoryEntry(attributes), next);\n case 'symlink':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new SymbolicLinkEntry(attributes), next);\n case 'link':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new LinkEntry(attributes), next);\n case 'file':\n return nextCallback(null, new FileEntry(attributes, stream, iterator.lock), next);\n }\n\n stream.resume(); // drain stream\n return nextCallback(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\n // Resume parsing to emit any pending entry\n // For first call (next is null), this triggers the first entry emission\n // For subsequent calls, next() unlocks the parser which then processes the next header\n if (next) {\n next();\n } else {\n // First call - resume to emit any pending entry\n extract.resume();\n }\n}\n"],"names":["once","DirectoryEntry","LinkEntry","SymbolicLinkEntry","path","FileEntry","_setImmediate","setImmediate","process","nextTick","setImmediateFallback","fn","setTimeout","nextEntry","next","iterator","callback","extract","Error","nextCallback","err","entry","removeListener","onEntry","onError","onEnd","push","bind","
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/nextEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';\nimport path from 'path';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\n// Node 0.8 compatible setImmediate (setImmediate was added in Node 0.10)\nconst _setImmediate =\n typeof setImmediate === 'function'\n ? setImmediate\n : typeof process !== 'undefined' && typeof process.nextTick === 'function'\n ? process.nextTick\n : function setImmediateFallback(fn: () => void) {\n setTimeout(fn, 0);\n };\n\nexport type TarNext = () => undefined;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => undefined;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): undefined {\n // Guard: bail early if iterator already ended\n if (!iterator.lock || iterator.isDone()) {\n return callback(null, { done: true, value: null });\n }\n\n const extract = iterator.extract;\n if (!extract) return callback(new Error('Extract missing'));\n\n const nextCallback = once((err?: Error, entry?: Entry, next?: TarNext) => {\n extract.removeListener('entry', onEntry);\n extract.removeListener('error', onError);\n extract.removeListener('finish', onEnd);\n\n // keep processing\n if (entry) iterator.push(nextEntry.bind(null, next));\n\n // Use setImmediate to defer the callback invocation\n // This ensures proper async behavior with the BaseIterator\n _setImmediate(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n });\n }) as NextCallback;\n\n const onError = callback;\n const onEnd = callback.bind(null, null);\n const onEntry = function onEntry(header, stream, next: TarNext) {\n // Guard: skip if iterator already ended (stale lock)\n if (!iterator.lock || iterator.isDone()) {\n stream.resume(); // drain stream\n return nextCallback(null, null, next);\n }\n\n const attributes = { ...header };\n attributes.path = header.name.split(path.sep).filter(Boolean).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 nextCallback(null, new DirectoryEntry(attributes), next);\n case 'symlink':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new SymbolicLinkEntry(attributes), next);\n case 'link':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new LinkEntry(attributes), next);\n case 'file':\n return nextCallback(null, new FileEntry(attributes, stream, iterator.lock), next);\n }\n\n stream.resume(); // drain stream\n return nextCallback(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\n // Resume parsing to emit any pending entry\n // For first call (next is null), this triggers the first entry emission\n // For subsequent calls, next() unlocks the parser which then processes the next header\n if (next) {\n next();\n } else {\n // First call - resume to emit any pending entry\n extract.resume();\n }\n}\n"],"names":["once","DirectoryEntry","LinkEntry","SymbolicLinkEntry","path","FileEntry","_setImmediate","setImmediate","process","nextTick","setImmediateFallback","fn","setTimeout","nextEntry","next","iterator","callback","lock","isDone","done","value","extract","Error","nextCallback","err","entry","removeListener","onEntry","onError","onEnd","push","bind","header","stream","resume","attributes","name","split","sep","filter","Boolean","join","mtime","Date","type","linkpath","linkname","on"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tar-iterator",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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",
|