extract-base-iterator 2.5.0 → 2.6.0

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.
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Lock - Reference counting for iterator lifecycle
3
+ *
4
+ * Ensures the iterator doesn't complete until all entries have been processed.
5
+ * Uses cleanup registration pattern so each iterator can register its specific
6
+ * cleanup functions (e.g., close file descriptors, delete temp files, end parsers).
7
+ *
8
+ * Usage:
9
+ * const lock = new Lock();
10
+ * lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);
11
+ * lock.registerCleanup(() => { this.extract.end(); });
12
+ * lock.registerCleanup(() => { fs.unlinkSync(this.tempPath); });
13
+ *
14
+ * // For each entry:
15
+ * lock.retain();
16
+ * // ... when entry is consumed:
17
+ * lock.release();
18
+ *
19
+ * // When iteration complete:
20
+ * lock.err = err; // optional error
21
+ * lock.release(); // Initial count
22
+ */
23
+ export type CleanupFn = () => void;
24
+ export default class Lock {
25
+ private count;
26
+ private cleanupFns;
27
+ /** Error to pass to onDestroy callback */
28
+ err: Error | null;
29
+ /** Called after all cleanups when count reaches 0 */
30
+ onDestroy: ((err: Error | null) => void) | null;
31
+ /**
32
+ * Register a cleanup function to be called when the lock is destroyed.
33
+ * Cleanup functions are called in registration order, before onDestroy.
34
+ * @param fn Cleanup function (should not throw)
35
+ */
36
+ registerCleanup(fn: CleanupFn): void;
37
+ /**
38
+ * Increment reference count.
39
+ * Call when starting to process a new entry.
40
+ */
41
+ retain(): void;
42
+ /**
43
+ * Decrement reference count.
44
+ * Call when an entry has been fully consumed.
45
+ * When count reaches 0, cleanup is triggered.
46
+ */
47
+ release(): void;
48
+ /**
49
+ * Internal cleanup - called when reference count reaches 0
50
+ */
51
+ private _destroy;
52
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Lock - Reference counting for iterator lifecycle
3
+ *
4
+ * Ensures the iterator doesn't complete until all entries have been processed.
5
+ * Uses cleanup registration pattern so each iterator can register its specific
6
+ * cleanup functions (e.g., close file descriptors, delete temp files, end parsers).
7
+ *
8
+ * Usage:
9
+ * const lock = new Lock();
10
+ * lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);
11
+ * lock.registerCleanup(() => { this.extract.end(); });
12
+ * lock.registerCleanup(() => { fs.unlinkSync(this.tempPath); });
13
+ *
14
+ * // For each entry:
15
+ * lock.retain();
16
+ * // ... when entry is consumed:
17
+ * lock.release();
18
+ *
19
+ * // When iteration complete:
20
+ * lock.err = err; // optional error
21
+ * lock.release(); // Initial count
22
+ */
23
+ export type CleanupFn = () => void;
24
+ export default class Lock {
25
+ private count;
26
+ private cleanupFns;
27
+ /** Error to pass to onDestroy callback */
28
+ err: Error | null;
29
+ /** Called after all cleanups when count reaches 0 */
30
+ onDestroy: ((err: Error | null) => void) | null;
31
+ /**
32
+ * Register a cleanup function to be called when the lock is destroyed.
33
+ * Cleanup functions are called in registration order, before onDestroy.
34
+ * @param fn Cleanup function (should not throw)
35
+ */
36
+ registerCleanup(fn: CleanupFn): void;
37
+ /**
38
+ * Increment reference count.
39
+ * Call when starting to process a new entry.
40
+ */
41
+ retain(): void;
42
+ /**
43
+ * Decrement reference count.
44
+ * Call when an entry has been fully consumed.
45
+ * When count reaches 0, cleanup is triggered.
46
+ */
47
+ release(): void;
48
+ /**
49
+ * Internal cleanup - called when reference count reaches 0
50
+ */
51
+ private _destroy;
52
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Lock - Reference counting for iterator lifecycle
3
+ *
4
+ * Ensures the iterator doesn't complete until all entries have been processed.
5
+ * Uses cleanup registration pattern so each iterator can register its specific
6
+ * cleanup functions (e.g., close file descriptors, delete temp files, end parsers).
7
+ *
8
+ * Usage:
9
+ * const lock = new Lock();
10
+ * lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);
11
+ * lock.registerCleanup(() => { this.extract.end(); });
12
+ * lock.registerCleanup(() => { fs.unlinkSync(this.tempPath); });
13
+ *
14
+ * // For each entry:
15
+ * lock.retain();
16
+ * // ... when entry is consumed:
17
+ * lock.release();
18
+ *
19
+ * // When iteration complete:
20
+ * lock.err = err; // optional error
21
+ * lock.release(); // Initial count
22
+ */ "use strict";
23
+ Object.defineProperty(exports, "__esModule", {
24
+ value: true
25
+ });
26
+ Object.defineProperty(exports, "default", {
27
+ enumerable: true,
28
+ get: function() {
29
+ return Lock;
30
+ }
31
+ });
32
+ function _class_call_check(instance, Constructor) {
33
+ if (!(instance instanceof Constructor)) {
34
+ throw new TypeError("Cannot call a class as a function");
35
+ }
36
+ }
37
+ var Lock = /*#__PURE__*/ function() {
38
+ "use strict";
39
+ function Lock() {
40
+ _class_call_check(this, Lock);
41
+ this.count = 1;
42
+ this.cleanupFns = [];
43
+ /** Error to pass to onDestroy callback */ this.err = null;
44
+ /** Called after all cleanups when count reaches 0 */ this.onDestroy = null;
45
+ }
46
+ var _proto = Lock.prototype;
47
+ /**
48
+ * Register a cleanup function to be called when the lock is destroyed.
49
+ * Cleanup functions are called in registration order, before onDestroy.
50
+ * @param fn Cleanup function (should not throw)
51
+ */ _proto.registerCleanup = function registerCleanup(fn) {
52
+ this.cleanupFns.push(fn);
53
+ };
54
+ /**
55
+ * Increment reference count.
56
+ * Call when starting to process a new entry.
57
+ */ _proto.retain = function retain() {
58
+ this.count++;
59
+ };
60
+ /**
61
+ * Decrement reference count.
62
+ * Call when an entry has been fully consumed.
63
+ * When count reaches 0, cleanup is triggered.
64
+ */ _proto.release = function release() {
65
+ if (this.count <= 0) {
66
+ throw new Error('Lock count is corrupted');
67
+ }
68
+ this.count--;
69
+ if (this.count === 0) {
70
+ this._destroy();
71
+ }
72
+ };
73
+ /**
74
+ * Internal cleanup - called when reference count reaches 0
75
+ */ _proto._destroy = function _destroy() {
76
+ // Run all registered cleanup functions in order
77
+ // Note: Use traditional for loop for Node 0.8 compatibility (no Symbol.iterator)
78
+ var fns = this.cleanupFns;
79
+ for(var i = 0; i < fns.length; i++){
80
+ try {
81
+ fns[i]();
82
+ } catch (_e) {
83
+ // Ignore cleanup errors to ensure all cleanup runs
84
+ }
85
+ }
86
+ this.cleanupFns = [];
87
+ // Call onDestroy callback LAST (typically calls iterator.end())
88
+ if (this.onDestroy) {
89
+ this.onDestroy(this.err);
90
+ this.onDestroy = null;
91
+ }
92
+ };
93
+ return Lock;
94
+ }();
95
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/Lock.ts"],"sourcesContent":["/**\n * Lock - Reference counting for iterator lifecycle\n *\n * Ensures the iterator doesn't complete until all entries have been processed.\n * Uses cleanup registration pattern so each iterator can register its specific\n * cleanup functions (e.g., close file descriptors, delete temp files, end parsers).\n *\n * Usage:\n * const lock = new Lock();\n * lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);\n * lock.registerCleanup(() => { this.extract.end(); });\n * lock.registerCleanup(() => { fs.unlinkSync(this.tempPath); });\n *\n * // For each entry:\n * lock.retain();\n * // ... when entry is consumed:\n * lock.release();\n *\n * // When iteration complete:\n * lock.err = err; // optional error\n * lock.release(); // Initial count\n */\n\nexport type CleanupFn = () => void;\n\nexport default class Lock {\n private count = 1;\n private cleanupFns: CleanupFn[] = [];\n\n /** Error to pass to onDestroy callback */\n err: Error | null = null;\n\n /** Called after all cleanups when count reaches 0 */\n onDestroy: ((err: Error | null) => void) | null = null;\n\n /**\n * Register a cleanup function to be called when the lock is destroyed.\n * Cleanup functions are called in registration order, before onDestroy.\n * @param fn Cleanup function (should not throw)\n */\n registerCleanup(fn: CleanupFn): void {\n this.cleanupFns.push(fn);\n }\n\n /**\n * Increment reference count.\n * Call when starting to process a new entry.\n */\n retain(): void {\n this.count++;\n }\n\n /**\n * Decrement reference count.\n * Call when an entry has been fully consumed.\n * When count reaches 0, cleanup is triggered.\n */\n release(): void {\n if (this.count <= 0) {\n throw new Error('Lock count is corrupted');\n }\n this.count--;\n if (this.count === 0) {\n this._destroy();\n }\n }\n\n /**\n * Internal cleanup - called when reference count reaches 0\n */\n private _destroy(): void {\n // Run all registered cleanup functions in order\n // Note: Use traditional for loop for Node 0.8 compatibility (no Symbol.iterator)\n const fns = this.cleanupFns;\n for (let i = 0; i < fns.length; i++) {\n try {\n fns[i]();\n } catch (_e) {\n // Ignore cleanup errors to ensure all cleanup runs\n }\n }\n this.cleanupFns = [];\n\n // Call onDestroy callback LAST (typically calls iterator.end())\n if (this.onDestroy) {\n this.onDestroy(this.err);\n this.onDestroy = null;\n }\n }\n}\n"],"names":["Lock","count","cleanupFns","err","onDestroy","registerCleanup","fn","push","retain","release","Error","_destroy","fns","i","length","_e"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;CAqBC;;;;;;;eAIoBA;;;;;;;;AAAN,IAAA,AAAMA,qBAAN;;aAAMA;gCAAAA;aACXC,QAAQ;aACRC,aAA0B,EAAE;QAEpC,wCAAwC,QACxCC,MAAoB;QAEpB,mDAAmD,QACnDC,YAAkD;;iBAR/BJ;IAUnB;;;;GAIC,GACDK,OAAAA,eAEC,GAFDA,SAAAA,gBAAgBC,EAAa;QAC3B,IAAI,CAACJ,UAAU,CAACK,IAAI,CAACD;IACvB;IAEA;;;GAGC,GACDE,OAAAA,MAEC,GAFDA,SAAAA;QACE,IAAI,CAACP,KAAK;IACZ;IAEA;;;;GAIC,GACDQ,OAAAA,OAQC,GARDA,SAAAA;QACE,IAAI,IAAI,CAACR,KAAK,IAAI,GAAG;YACnB,MAAM,IAAIS,MAAM;QAClB;QACA,IAAI,CAACT,KAAK;QACV,IAAI,IAAI,CAACA,KAAK,KAAK,GAAG;YACpB,IAAI,CAACU,QAAQ;QACf;IACF;IAEA;;GAEC,GACD,OAAQA,QAkBP,GAlBD,SAAQA;QACN,gDAAgD;QAChD,iFAAiF;QACjF,IAAMC,MAAM,IAAI,CAACV,UAAU;QAC3B,IAAK,IAAIW,IAAI,GAAGA,IAAID,IAAIE,MAAM,EAAED,IAAK;YACnC,IAAI;gBACFD,GAAG,CAACC,EAAE;YACR,EAAE,OAAOE,IAAI;YACX,mDAAmD;YACrD;QACF;QACA,IAAI,CAACb,UAAU,GAAG,EAAE;QAEpB,gEAAgE;QAChE,IAAI,IAAI,CAACE,SAAS,EAAE;YAClB,IAAI,CAACA,SAAS,CAAC,IAAI,CAACD,GAAG;YACvB,IAAI,CAACC,SAAS,GAAG;QACnB;IACF;WA/DmBJ"}
@@ -13,3 +13,4 @@ export { default as BufferList } from './BufferList.js';
13
13
  export { allocBuffer, allocBufferUnsafe, bufferCompare, bufferConcat, bufferEquals, bufferFrom, bufferSliceCopy, createInflateRawStream, inflateRaw, isNaN, objectAssign, readUInt64LE, setImmediateFn, writeUInt64LE, } from './compat.js';
14
14
  export { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.js';
15
15
  export { default as EntryStream } from './EntryStream.js';
16
+ export { type CleanupFn, default as Lock } from './Lock.js';
@@ -13,3 +13,4 @@ export { default as BufferList } from './BufferList.js';
13
13
  export { allocBuffer, allocBufferUnsafe, bufferCompare, bufferConcat, bufferEquals, bufferFrom, bufferSliceCopy, createInflateRawStream, inflateRaw, isNaN, objectAssign, readUInt64LE, setImmediateFn, writeUInt64LE, } from './compat.js';
14
14
  export { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.js';
15
15
  export { default as EntryStream } from './EntryStream.js';
16
+ export { type CleanupFn, default as Lock } from './Lock.js';
@@ -25,6 +25,9 @@ _export(exports, {
25
25
  get EntryStream () {
26
26
  return _EntryStreamts.default;
27
27
  },
28
+ get Lock () {
29
+ return _Lockts.default;
30
+ },
28
31
  get allocBuffer () {
29
32
  return _compatts.allocBuffer;
30
33
  },
@@ -84,6 +87,7 @@ var _BufferListts = /*#__PURE__*/ _interop_require_default(require("./BufferList
84
87
  var _compatts = require("./compat.js");
85
88
  var _crc32ts = require("./crc32.js");
86
89
  var _EntryStreamts = /*#__PURE__*/ _interop_require_default(require("./EntryStream.js"));
90
+ var _Lockts = /*#__PURE__*/ _interop_require_default(require("./Lock.js"));
87
91
  function _interop_require_default(obj) {
88
92
  return obj && obj.__esModule ? obj : {
89
93
  default: obj
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/index.ts"],"sourcesContent":["/**\n * Shared utilities for iterator libraries\n *\n * These utilities are designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n *\n * All utilities support Node.js 0.8+\n */\n\nexport { default as BufferList } from './BufferList.ts';\nexport {\n allocBuffer,\n allocBufferUnsafe,\n bufferCompare,\n bufferConcat,\n bufferEquals,\n bufferFrom,\n bufferSliceCopy,\n createInflateRawStream,\n inflateRaw,\n isNaN,\n objectAssign,\n readUInt64LE,\n setImmediateFn,\n writeUInt64LE,\n} from './compat.ts';\nexport { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.ts';\nexport { default as EntryStream } from './EntryStream.ts';\n"],"names":["BufferList","EntryStream","allocBuffer","allocBufferUnsafe","bufferCompare","bufferConcat","bufferEquals","bufferFrom","bufferSliceCopy","crc32","crc32Region","createInflateRawStream","inflateRaw","isNaN","objectAssign","readUInt64LE","setImmediateFn","verifyCrc32","verifyCrc32Region","writeUInt64LE"],"mappings":"AAAA;;;;;;;;;;CAUC;;;;;;;;;;;QAEmBA;eAAAA,qBAAU;;QAkBVC;eAAAA,sBAAW;;QAhB7BC;eAAAA,qBAAW;;QACXC;eAAAA,2BAAiB;;QACjBC;eAAAA,uBAAa;;QACbC;eAAAA,sBAAY;;QACZC;eAAAA,sBAAY;;QACZC;eAAAA,oBAAU;;QACVC;eAAAA,yBAAe;;QASRC;eAAAA,cAAK;;QAAEC;eAAAA,oBAAW;;QARzBC;eAAAA,gCAAsB;;QACtBC;eAAAA,oBAAU;;QACVC;eAAAA,eAAK;;QACLC;eAAAA,sBAAY;;QACZC;eAAAA,sBAAY;;QACZC;eAAAA,wBAAc;;QAGaC;eAAAA,oBAAW;;QAAEC;eAAAA,0BAAiB;;QAFzDC;eAAAA,uBAAa;;;mEAfuB;wBAgB/B;uBAC4D;oEAC5B"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/index.ts"],"sourcesContent":["/**\n * Shared utilities for iterator libraries\n *\n * These utilities are designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n *\n * All utilities support Node.js 0.8+\n */\n\nexport { default as BufferList } from './BufferList.ts';\nexport {\n allocBuffer,\n allocBufferUnsafe,\n bufferCompare,\n bufferConcat,\n bufferEquals,\n bufferFrom,\n bufferSliceCopy,\n createInflateRawStream,\n inflateRaw,\n isNaN,\n objectAssign,\n readUInt64LE,\n setImmediateFn,\n writeUInt64LE,\n} from './compat.ts';\nexport { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.ts';\nexport { default as EntryStream } from './EntryStream.ts';\nexport { type CleanupFn, default as Lock } from './Lock.ts';\n"],"names":["BufferList","EntryStream","Lock","allocBuffer","allocBufferUnsafe","bufferCompare","bufferConcat","bufferEquals","bufferFrom","bufferSliceCopy","crc32","crc32Region","createInflateRawStream","inflateRaw","isNaN","objectAssign","readUInt64LE","setImmediateFn","verifyCrc32","verifyCrc32Region","writeUInt64LE"],"mappings":"AAAA;;;;;;;;;;CAUC;;;;;;;;;;;QAEmBA;eAAAA,qBAAU;;QAkBVC;eAAAA,sBAAW;;QACKC;eAAAA,eAAI;;QAjBtCC;eAAAA,qBAAW;;QACXC;eAAAA,2BAAiB;;QACjBC;eAAAA,uBAAa;;QACbC;eAAAA,sBAAY;;QACZC;eAAAA,sBAAY;;QACZC;eAAAA,oBAAU;;QACVC;eAAAA,yBAAe;;QASRC;eAAAA,cAAK;;QAAEC;eAAAA,oBAAW;;QARzBC;eAAAA,gCAAsB;;QACtBC;eAAAA,oBAAU;;QACVC;eAAAA,eAAK;;QACLC;eAAAA,sBAAY;;QACZC;eAAAA,sBAAY;;QACZC;eAAAA,wBAAc;;QAGaC;eAAAA,oBAAW;;QAAEC;eAAAA,0BAAiB;;QAFzDC;eAAAA,uBAAa;;;mEAfuB;wBAgB/B;uBAC4D;oEAC5B;6DACS"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Lock - Reference counting for iterator lifecycle
3
+ *
4
+ * Ensures the iterator doesn't complete until all entries have been processed.
5
+ * Uses cleanup registration pattern so each iterator can register its specific
6
+ * cleanup functions (e.g., close file descriptors, delete temp files, end parsers).
7
+ *
8
+ * Usage:
9
+ * const lock = new Lock();
10
+ * lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);
11
+ * lock.registerCleanup(() => { this.extract.end(); });
12
+ * lock.registerCleanup(() => { fs.unlinkSync(this.tempPath); });
13
+ *
14
+ * // For each entry:
15
+ * lock.retain();
16
+ * // ... when entry is consumed:
17
+ * lock.release();
18
+ *
19
+ * // When iteration complete:
20
+ * lock.err = err; // optional error
21
+ * lock.release(); // Initial count
22
+ */
23
+ export type CleanupFn = () => void;
24
+ export default class Lock {
25
+ private count;
26
+ private cleanupFns;
27
+ /** Error to pass to onDestroy callback */
28
+ err: Error | null;
29
+ /** Called after all cleanups when count reaches 0 */
30
+ onDestroy: ((err: Error | null) => void) | null;
31
+ /**
32
+ * Register a cleanup function to be called when the lock is destroyed.
33
+ * Cleanup functions are called in registration order, before onDestroy.
34
+ * @param fn Cleanup function (should not throw)
35
+ */
36
+ registerCleanup(fn: CleanupFn): void;
37
+ /**
38
+ * Increment reference count.
39
+ * Call when starting to process a new entry.
40
+ */
41
+ retain(): void;
42
+ /**
43
+ * Decrement reference count.
44
+ * Call when an entry has been fully consumed.
45
+ * When count reaches 0, cleanup is triggered.
46
+ */
47
+ release(): void;
48
+ /**
49
+ * Internal cleanup - called when reference count reaches 0
50
+ */
51
+ private _destroy;
52
+ }
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Lock - Reference counting for iterator lifecycle
3
+ *
4
+ * Ensures the iterator doesn't complete until all entries have been processed.
5
+ * Uses cleanup registration pattern so each iterator can register its specific
6
+ * cleanup functions (e.g., close file descriptors, delete temp files, end parsers).
7
+ *
8
+ * Usage:
9
+ * const lock = new Lock();
10
+ * lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);
11
+ * lock.registerCleanup(() => { this.extract.end(); });
12
+ * lock.registerCleanup(() => { fs.unlinkSync(this.tempPath); });
13
+ *
14
+ * // For each entry:
15
+ * lock.retain();
16
+ * // ... when entry is consumed:
17
+ * lock.release();
18
+ *
19
+ * // When iteration complete:
20
+ * lock.err = err; // optional error
21
+ * lock.release(); // Initial count
22
+ */ let Lock = class Lock {
23
+ /**
24
+ * Register a cleanup function to be called when the lock is destroyed.
25
+ * Cleanup functions are called in registration order, before onDestroy.
26
+ * @param fn Cleanup function (should not throw)
27
+ */ registerCleanup(fn) {
28
+ this.cleanupFns.push(fn);
29
+ }
30
+ /**
31
+ * Increment reference count.
32
+ * Call when starting to process a new entry.
33
+ */ retain() {
34
+ this.count++;
35
+ }
36
+ /**
37
+ * Decrement reference count.
38
+ * Call when an entry has been fully consumed.
39
+ * When count reaches 0, cleanup is triggered.
40
+ */ release() {
41
+ if (this.count <= 0) {
42
+ throw new Error('Lock count is corrupted');
43
+ }
44
+ this.count--;
45
+ if (this.count === 0) {
46
+ this._destroy();
47
+ }
48
+ }
49
+ /**
50
+ * Internal cleanup - called when reference count reaches 0
51
+ */ _destroy() {
52
+ // Run all registered cleanup functions in order
53
+ // Note: Use traditional for loop for Node 0.8 compatibility (no Symbol.iterator)
54
+ const fns = this.cleanupFns;
55
+ for(let i = 0; i < fns.length; i++){
56
+ try {
57
+ fns[i]();
58
+ } catch (_e) {
59
+ // Ignore cleanup errors to ensure all cleanup runs
60
+ }
61
+ }
62
+ this.cleanupFns = [];
63
+ // Call onDestroy callback LAST (typically calls iterator.end())
64
+ if (this.onDestroy) {
65
+ this.onDestroy(this.err);
66
+ this.onDestroy = null;
67
+ }
68
+ }
69
+ constructor(){
70
+ this.count = 1;
71
+ this.cleanupFns = [];
72
+ /** Error to pass to onDestroy callback */ this.err = null;
73
+ /** Called after all cleanups when count reaches 0 */ this.onDestroy = null;
74
+ }
75
+ };
76
+ export { Lock as default };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/Lock.ts"],"sourcesContent":["/**\n * Lock - Reference counting for iterator lifecycle\n *\n * Ensures the iterator doesn't complete until all entries have been processed.\n * Uses cleanup registration pattern so each iterator can register its specific\n * cleanup functions (e.g., close file descriptors, delete temp files, end parsers).\n *\n * Usage:\n * const lock = new Lock();\n * lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);\n * lock.registerCleanup(() => { this.extract.end(); });\n * lock.registerCleanup(() => { fs.unlinkSync(this.tempPath); });\n *\n * // For each entry:\n * lock.retain();\n * // ... when entry is consumed:\n * lock.release();\n *\n * // When iteration complete:\n * lock.err = err; // optional error\n * lock.release(); // Initial count\n */\n\nexport type CleanupFn = () => void;\n\nexport default class Lock {\n private count = 1;\n private cleanupFns: CleanupFn[] = [];\n\n /** Error to pass to onDestroy callback */\n err: Error | null = null;\n\n /** Called after all cleanups when count reaches 0 */\n onDestroy: ((err: Error | null) => void) | null = null;\n\n /**\n * Register a cleanup function to be called when the lock is destroyed.\n * Cleanup functions are called in registration order, before onDestroy.\n * @param fn Cleanup function (should not throw)\n */\n registerCleanup(fn: CleanupFn): void {\n this.cleanupFns.push(fn);\n }\n\n /**\n * Increment reference count.\n * Call when starting to process a new entry.\n */\n retain(): void {\n this.count++;\n }\n\n /**\n * Decrement reference count.\n * Call when an entry has been fully consumed.\n * When count reaches 0, cleanup is triggered.\n */\n release(): void {\n if (this.count <= 0) {\n throw new Error('Lock count is corrupted');\n }\n this.count--;\n if (this.count === 0) {\n this._destroy();\n }\n }\n\n /**\n * Internal cleanup - called when reference count reaches 0\n */\n private _destroy(): void {\n // Run all registered cleanup functions in order\n // Note: Use traditional for loop for Node 0.8 compatibility (no Symbol.iterator)\n const fns = this.cleanupFns;\n for (let i = 0; i < fns.length; i++) {\n try {\n fns[i]();\n } catch (_e) {\n // Ignore cleanup errors to ensure all cleanup runs\n }\n }\n this.cleanupFns = [];\n\n // Call onDestroy callback LAST (typically calls iterator.end())\n if (this.onDestroy) {\n this.onDestroy(this.err);\n this.onDestroy = null;\n }\n }\n}\n"],"names":["Lock","registerCleanup","fn","cleanupFns","push","retain","count","release","Error","_destroy","fns","i","length","_e","onDestroy","err"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;CAqBC,GAIc,IAAA,AAAMA,OAAN,MAAMA;IAUnB;;;;GAIC,GACDC,gBAAgBC,EAAa,EAAQ;QACnC,IAAI,CAACC,UAAU,CAACC,IAAI,CAACF;IACvB;IAEA;;;GAGC,GACDG,SAAe;QACb,IAAI,CAACC,KAAK;IACZ;IAEA;;;;GAIC,GACDC,UAAgB;QACd,IAAI,IAAI,CAACD,KAAK,IAAI,GAAG;YACnB,MAAM,IAAIE,MAAM;QAClB;QACA,IAAI,CAACF,KAAK;QACV,IAAI,IAAI,CAACA,KAAK,KAAK,GAAG;YACpB,IAAI,CAACG,QAAQ;QACf;IACF;IAEA;;GAEC,GACD,AAAQA,WAAiB;QACvB,gDAAgD;QAChD,iFAAiF;QACjF,MAAMC,MAAM,IAAI,CAACP,UAAU;QAC3B,IAAK,IAAIQ,IAAI,GAAGA,IAAID,IAAIE,MAAM,EAAED,IAAK;YACnC,IAAI;gBACFD,GAAG,CAACC,EAAE;YACR,EAAE,OAAOE,IAAI;YACX,mDAAmD;YACrD;QACF;QACA,IAAI,CAACV,UAAU,GAAG,EAAE;QAEpB,gEAAgE;QAChE,IAAI,IAAI,CAACW,SAAS,EAAE;YAClB,IAAI,CAACA,SAAS,CAAC,IAAI,CAACC,GAAG;YACvB,IAAI,CAACD,SAAS,GAAG;QACnB;IACF;;aA9DQR,QAAQ;aACRH,aAA0B,EAAE;QAEpC,wCAAwC,QACxCY,MAAoB;QAEpB,mDAAmD,QACnDD,YAAkD;;AAwDpD;AAhEA,SAAqBd,kBAgEpB"}
@@ -13,3 +13,4 @@ export { default as BufferList } from './BufferList.js';
13
13
  export { allocBuffer, allocBufferUnsafe, bufferCompare, bufferConcat, bufferEquals, bufferFrom, bufferSliceCopy, createInflateRawStream, inflateRaw, isNaN, objectAssign, readUInt64LE, setImmediateFn, writeUInt64LE, } from './compat.js';
14
14
  export { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.js';
15
15
  export { default as EntryStream } from './EntryStream.js';
16
+ export { type CleanupFn, default as Lock } from './Lock.js';
@@ -12,3 +12,4 @@
12
12
  export { allocBuffer, allocBufferUnsafe, bufferCompare, bufferConcat, bufferEquals, bufferFrom, bufferSliceCopy, createInflateRawStream, inflateRaw, isNaN, objectAssign, readUInt64LE, setImmediateFn, writeUInt64LE } from './compat.js';
13
13
  export { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.js';
14
14
  export { default as EntryStream } from './EntryStream.js';
15
+ export { default as Lock } from './Lock.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/index.ts"],"sourcesContent":["/**\n * Shared utilities for iterator libraries\n *\n * These utilities are designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n *\n * All utilities support Node.js 0.8+\n */\n\nexport { default as BufferList } from './BufferList.ts';\nexport {\n allocBuffer,\n allocBufferUnsafe,\n bufferCompare,\n bufferConcat,\n bufferEquals,\n bufferFrom,\n bufferSliceCopy,\n createInflateRawStream,\n inflateRaw,\n isNaN,\n objectAssign,\n readUInt64LE,\n setImmediateFn,\n writeUInt64LE,\n} from './compat.ts';\nexport { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.ts';\nexport { default as EntryStream } from './EntryStream.ts';\n"],"names":["default","BufferList","allocBuffer","allocBufferUnsafe","bufferCompare","bufferConcat","bufferEquals","bufferFrom","bufferSliceCopy","createInflateRawStream","inflateRaw","isNaN","objectAssign","readUInt64LE","setImmediateFn","writeUInt64LE","crc32","crc32Region","verifyCrc32","verifyCrc32Region","EntryStream"],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,SAASA,WAAWC,UAAU,QAAQ,kBAAkB;AACxD,SACEC,WAAW,EACXC,iBAAiB,EACjBC,aAAa,EACbC,YAAY,EACZC,YAAY,EACZC,UAAU,EACVC,eAAe,EACfC,sBAAsB,EACtBC,UAAU,EACVC,KAAK,EACLC,YAAY,EACZC,YAAY,EACZC,cAAc,EACdC,aAAa,QACR,cAAc;AACrB,SAASC,KAAK,EAAEC,WAAW,EAAEC,WAAW,EAAEC,iBAAiB,QAAQ,aAAa;AAChF,SAASnB,WAAWoB,WAAW,QAAQ,mBAAmB"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/extract-base-iterator/src/shared/index.ts"],"sourcesContent":["/**\n * Shared utilities for iterator libraries\n *\n * These utilities are designed to be used by:\n * - zip-iterator\n * - 7z-iterator\n * - tar-iterator\n * - Any other archive iterator library\n *\n * All utilities support Node.js 0.8+\n */\n\nexport { default as BufferList } from './BufferList.ts';\nexport {\n allocBuffer,\n allocBufferUnsafe,\n bufferCompare,\n bufferConcat,\n bufferEquals,\n bufferFrom,\n bufferSliceCopy,\n createInflateRawStream,\n inflateRaw,\n isNaN,\n objectAssign,\n readUInt64LE,\n setImmediateFn,\n writeUInt64LE,\n} from './compat.ts';\nexport { crc32, crc32Region, verifyCrc32, verifyCrc32Region } from './crc32.ts';\nexport { default as EntryStream } from './EntryStream.ts';\nexport { type CleanupFn, default as Lock } from './Lock.ts';\n"],"names":["default","BufferList","allocBuffer","allocBufferUnsafe","bufferCompare","bufferConcat","bufferEquals","bufferFrom","bufferSliceCopy","createInflateRawStream","inflateRaw","isNaN","objectAssign","readUInt64LE","setImmediateFn","writeUInt64LE","crc32","crc32Region","verifyCrc32","verifyCrc32Region","EntryStream","Lock"],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,SAASA,WAAWC,UAAU,QAAQ,kBAAkB;AACxD,SACEC,WAAW,EACXC,iBAAiB,EACjBC,aAAa,EACbC,YAAY,EACZC,YAAY,EACZC,UAAU,EACVC,eAAe,EACfC,sBAAsB,EACtBC,UAAU,EACVC,KAAK,EACLC,YAAY,EACZC,YAAY,EACZC,cAAc,EACdC,aAAa,QACR,cAAc;AACrB,SAASC,KAAK,EAAEC,WAAW,EAAEC,WAAW,EAAEC,iBAAiB,QAAQ,aAAa;AAChF,SAASnB,WAAWoB,WAAW,QAAQ,mBAAmB;AAC1D,SAAyBpB,WAAWqB,IAAI,QAAQ,YAAY"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extract-base-iterator",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Base iterator for extract iterators like tar-iterator and zip-iterator",
5
5
  "keywords": [
6
6
  "extract",
@@ -43,7 +43,7 @@
43
43
  "version": "tsds version"
44
44
  },
45
45
  "dependencies": {
46
- "fs-remove-compat": "^0.2.5",
46
+ "fs-remove-compat": "^1.0.0",
47
47
  "graceful-fs": "^4.2.11",
48
48
  "is-absolute": "^1.0.0",
49
49
  "lodash.compact": "^3.0.1",
@@ -60,7 +60,6 @@
60
60
  "cr": "^0.1.0",
61
61
  "fs-iterator": "^6.1.12",
62
62
  "fs-stats-spys": "^1.2.9",
63
- "lodash.find": "^4.6.0",
64
63
  "node-version-use": "*",
65
64
  "pinkie-promise": "*",
66
65
  "ts-dev-stack": "*",