tar-iterator 3.3.0 → 3.3.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.
@@ -93,12 +93,9 @@ var TarFileEntry = /*#__PURE__*/ function(FileEntry) {
93
93
  var _proto = TarFileEntry.prototype;
94
94
  _proto.create = function create(dest, options, callback) {
95
95
  var _this = this;
96
- if (typeof options === 'function') {
97
- callback = options;
98
- options = null;
99
- }
96
+ callback = typeof options === 'function' ? options : callback;
97
+ options = typeof options === 'function' ? {} : options || {};
100
98
  if (typeof callback === 'function') {
101
- options = options || {};
102
99
  return _extractbaseiterator.FileEntry.prototype.create.call(this, dest, options, function(err) {
103
100
  callback(err);
104
101
  if (_this.lock) {
@@ -108,7 +105,7 @@ var TarFileEntry = /*#__PURE__*/ function(FileEntry) {
108
105
  });
109
106
  }
110
107
  return new Promise(function(resolve, reject) {
111
- _this.create(dest, options, function(err, done) {
108
+ return _this.create(dest, options, function(err, done) {
112
109
  return err ? reject(err) : resolve(done);
113
110
  });
114
111
  });
@@ -127,11 +124,17 @@ var TarFileEntry = /*#__PURE__*/ function(FileEntry) {
127
124
  try {
128
125
  var writeStream = _fs.default.createWriteStream(fullPath);
129
126
  // Listen for errors on source stream (errors don't propagate through pipe)
130
- stream.on('error', function(err) {
131
- // Destroy the write stream on source error
127
+ stream.on('error', function(streamErr) {
128
+ // Destroy the write stream on source error.
129
+ // On Node 0.8, destroy() emits 'close' before 'error'. Since on-one is listening
130
+ // for ['error', 'close', 'finish'], it catches 'close' first, calls our callback,
131
+ // and removes ALL listeners - including the 'error' listener. The subsequent EBADF
132
+ // error then fires with no handler, causing an uncaught exception.
133
+ // Adding a no-op error handler ensures there's always a listener for any error.
132
134
  var ws = writeStream;
135
+ writeStream.on('error', function() {});
133
136
  if (typeof ws.destroy === 'function') ws.destroy();
134
- cb(err);
137
+ cb(streamErr);
135
138
  });
136
139
  // Pipe and listen for write stream completion/errors
137
140
  stream.pipe(writeStream);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/FileEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n if (typeof callback === 'function') {\n options = options || {};\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n\n return new Promise((resolve, reject) => {\n this.create(dest, options as ExtractOptions, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void {\n if (!this.stream) {\n callback(new Error('FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null; // Prevent reuse\n\n // Use once since errors can come from either stream\n const cb = once((err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally\n });\n\n try {\n const writeStream = fs.createWriteStream(fullPath);\n\n // Listen for errors on source stream (errors don't propagate through pipe)\n stream.on('error', (err: Error) => {\n // Destroy the write stream on source error\n const ws = writeStream as fs.WriteStream & { destroy?: () => void };\n if (typeof ws.destroy === 'function') ws.destroy();\n cb(err);\n });\n\n // Pipe and listen for write stream completion/errors\n stream.pipe(writeStream);\n oo(writeStream, ['error', 'close', 'finish'], cb);\n } catch (err) {\n cb(err);\n }\n }\n\n destroy() {\n 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}\n"],"names":["TarFileEntry","attributes","stream","lock","retain","create","dest","options","callback","FileEntry","prototype","call","err","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","Error","cb","once","waitForAccess","writeStream","fs","createWriteStream","on","ws","destroy","pipe","oo","resume"],"mappings":";;;;;;;eAOqBA;;;iEAPJ;mCAC8E;yDAChF;4DACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAA,AAAMA,6BAAN;;cAAMA;aAAAA,aAIPC,UAA0B,EAAEC,MAA6B,EAAEC,IAAU;gCAJ9DH;;gBAKjB,kBALiBA;YAKXC;;QACN,MAAKC,MAAM,GAAGA;QACd,MAAKC,IAAI,GAAGA;QACZ,MAAKA,IAAI,CAACC,MAAM;;;iBARCJ;IAcnBK,OAAAA,MAmBC,GAnBDA,SAAAA,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B;;QACzF,IAAI,OAAOD,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACA,IAAI,OAAOC,aAAa,YAAY;YAClCD,UAAUA,WAAW,CAAC;YACtB,OAAOE,8BAAS,CAACC,SAAS,CAACL,MAAM,CAACM,IAAI,CAAC,IAAI,EAAEL,MAAMC,SAAS,SAACK;gBAC3DJ,SAASI;gBACT,IAAI,MAAKT,IAAI,EAAE;oBACb,MAAKA,IAAI,CAACU,OAAO;oBACjB,MAAKV,IAAI,GAAG;gBACd;YACF;QACF;QAEA,OAAO,IAAIW,QAAQ,SAACC,SAASC;YAC3B,MAAKX,MAAM,CAACC,MAAMC,SAA2B,SAACK,KAAaK;u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ource/iterators/tar-iterator/src/FileEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void {\n if (!this.stream) {\n callback(new Error('FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null; // Prevent reuse\n\n // Use once since errors can come from either stream\n const cb = once((err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally\n });\n\n try {\n const writeStream = fs.createWriteStream(fullPath);\n\n // Listen for errors on source stream (errors don't propagate through pipe)\n stream.on('error', (streamErr: Error) => {\n // Destroy the write stream on source error.\n // On Node 0.8, destroy() emits 'close' before 'error'. Since on-one is listening\n // for ['error', 'close', 'finish'], it catches 'close' first, calls our callback,\n // and removes ALL listeners - including the 'error' listener. The subsequent EBADF\n // error then fires with no handler, causing an uncaught exception.\n // Adding a no-op error handler ensures there's always a listener for any error.\n const ws = writeStream as fs.WriteStream & { destroy?: () => void };\n writeStream.on('error', () => {});\n if (typeof ws.destroy === 'function') ws.destroy();\n cb(streamErr);\n });\n\n // Pipe and listen for write stream completion/errors\n stream.pipe(writeStream);\n oo(writeStream, ['error', 'close', 'finish'], cb);\n } catch (err) {\n cb(err);\n }\n }\n\n destroy() {\n 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}\n"],"names":["TarFileEntry","attributes","stream","lock","retain","create","dest","options","callback","FileEntry","prototype","call","err","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","Error","cb","once","waitForAccess","writeStream","fs","createWriteStream","on","streamErr","ws","destroy","pipe","oo","resume"],"mappings":";;;;;;;eAOqBA;;;iEAPJ;mCAC8E;yDAChF;4DACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,IAAA,AAAMA,6BAAN;;cAAMA;aAAAA,aAIPC,UAA0B,EAAEC,MAA6B,EAAEC,IAAU;gCAJ9DH;;gBAKjB,kBALiBA;YAKXC;;QACN,MAAKC,MAAM,GAAGA;QACd,MAAKC,IAAI,GAAGA;QACZ,MAAKA,IAAI,CAACC,MAAM;;;iBARCJ;IAcnBK,OAAAA,MAeC,GAfDA,SAAAA,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B;;QACzFA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAE7D,IAAI,OAAOC,aAAa,YAAY;YAClC,OAAOC,8BAAS,CAACC,SAAS,CAACL,MAAM,CAACM,IAAI,CAAC,IAAI,EAAEL,MAAMC,SAAS,SAACK;gBAC3DJ,SAASI;gBACT,IAAI,MAAKT,I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AI,IAAI,CAACT,MAAM,EAAE;YACf,IAAI,CAACA,MAAM,CAACgC,MAAM,IAAI,eAAe;YACrC,IAAI,CAAChC,MAAM,GAAG;QAChB;QACA,IAAI,IAAI,CAACC,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACU,OAAO;YACjB,IAAI,CAACV,IAAI,GAAG;QACd;IACF;WAhFmBH;EAAqBS,8BAAS"}
@@ -60,8 +60,8 @@ function nextEntry(next, iterator, callback) {
60
60
  extract.removeListener('finish', onEnd);
61
61
  // keep processing
62
62
  if (entry) iterator.push(nextEntry.bind(null, next));
63
- // Defer the callback invocation to ensure proper async behavior with the BaseIterator
64
- setTimeout(function() {
63
+ // Avoid Zalgo: ensure callback is always async even when entry is available synchronously
64
+ process.nextTick(function() {
65
65
  err ? callback(err) : callback(null, entry ? {
66
66
  done: false,
67
67
  value: entry
@@ -69,7 +69,7 @@ function nextEntry(next, iterator, callback) {
69
69
  done: true,
70
70
  value: null
71
71
  });
72
- }, 0);
72
+ });
73
73
  });
74
74
  // Use nextCallback for all events to ensure once() wrapper is respected
75
75
  var onError = function(err) {
@@ -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, normalizePath, SymbolicLinkEntry } from 'extract-base-iterator';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\nexport type TarNext = () => void;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => void;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): void {\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 // Defer the callback invocation to ensure proper async behavior with the BaseIterator\n setTimeout(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n }, 0);\n }) as NextCallback;\n\n // Use nextCallback for all events to ensure once() wrapper is respected\n const onError = (err: Error) => nextCallback(err);\n const onEnd = () => nextCallback();\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 = normalizePath(header.name);\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","next","iterator","callback","lock","isDone","done","value","extract","Error","nextCallback","once","err","entry","removeListener","onEntry","onError","onEnd","push","bind","setTimeout","header","stream","resume","attributes","path","normalizePath","name","mtime","Date","type","DirectoryEntry","linkpath","linkname","SymbolicLinkEntry","LinkEntry","FileEntry","on"],"mappings":";;;;+BAUA;;;eAAw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rB,KAAK;gBACHR,OAAOC,MAAM,IAAI,eAAe;gBAChC,OAAOb,aAAa,MAAM,IAAIqB,mCAAc,CAACP,aAAavB;YAC5D,KAAK;gBACHqB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWQ,QAAQ,GAAGX,OAAOY,QAAQ;gBACrC,OAAOvB,aAAa,MAAM,IAAIwB,sCAAiB,CAACV,aAAavB;YAC/D,KAAK;gBACHqB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWQ,QAAQ,GAAGX,OAAOY,QAAQ;gBACrC,OAAOvB,aAAa,MAAM,IAAIyB,8BAAS,CAACX,aAAavB;YACvD,KAAK;gBACH,OAAOS,aAAa,MAAM,IAAI0B,oBAAS,CAACZ,YAAYF,QAAQpB,SAASE,IAAI,GAAGH;QAChF;QAEAqB,OAAOC,MAAM,IAAI,eAAe;QAChC,OAAOb,aAAa,IAAID,MAAM,AAAC,4BAA2C,OAAhBe,WAAWM,IAAI,IAAK,MAAM7B;IACtF;IAEAO,QAAQ6B,EAAE,CAAC,SAAStB;IACpBP,QAAQ6B,EAAE,CAAC,SAASrB;IACpBR,QAAQ6B,EAAE,CAAC,UAAUpB;IAErB,2CAA2C;IAC3C,wEAAwE;IACxE,uFAAuF;IACvF,IAAIhB,MAAM;QACRA;IACF,OAAO;QACL,gDAAgD;QAChDO,QAAQe,MAAM;IAChB;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/nextEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { DirectoryEntry, LinkEntry, normalizePath, SymbolicLinkEntry } from 'extract-base-iterator';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\nexport type TarNext = () => void;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => void;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): void {\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 // Avoid Zalgo: ensure callback is always async even when entry is available synchronously\n process.nextTick(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n });\n }) as NextCallback;\n\n // Use nextCallback for all events to ensure once() wrapper is respected\n const onError = (err: Error) => nextCallback(err);\n const onEnd = () => nextCallback();\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 = normalizePath(header.name);\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","next","iterator","callback","lock","isDone","done","value","extract","Error","nextCallback","once","err","entry","removeListener","onEntry","onError","onEnd","push","bind","process","nextTick","header","stream","resume","attributes","path","normalizePath","name","mtime","Date","type","DirectoryEntry","linkpath","linkname","SymbolicLinkEntry","LinkEntry","FileEntry","on"],"mappings":";;;;+BAUA;;;eAAwBA;;;iEAVP;mCAC2D;kEACtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQP,SAASA,UAAUC,IAAa,EAAEC,QAAkB,EAAEC,QAAuB;IAC1F,8CAA8C;IAC9C,IAAI,CAACD,SAASE,IAAI,IAAIF,SAASG,MAAM,IAAI;QACvC,OAAOF,SAAS,MAAM;YAAEG,MAAM;YAAMC,OAAO;QAAK;IAClD;IAEA,IAAMC,UAAUN,SAASM,OAAO;IAChC,IAAI,CAACA,SAAS,OAAOL,SAAS,IAAIM,MAAM;IAExC,IAAMC,eAAeC,IAAAA,mBAAI,EAAC,SAACC,KAAaC,OAAeZ;QACrDO,QAAQM,cAAc,CAAC,SAASC;QAChCP,QAAQM,cAAc,CAAC,SAASE;QAChCR,QAAQM,cAAc,CAAC,UAAUG;QAEjC,kBAAkB;QAClB,IAAIJ,OAAOX,SAASgB,IAAI,CAAClB,UAAUmB,IAAI,CAAC,MAAMlB;QAE9C,0FAA0F;QAC1FmB,QAAQC,QAAQ,CAAC;YACfT,MAAMT,SAASS,OAAOT,SAAS,MAAMU,QAAQ;gBAAEP,MAAM;gBAAOC,OAAOM;YAAM,IAAI;gBAAEP,MAAM;gBAAMC,OAAO;YAAK;QACzG;IACF;IAEA,wEAAwE;IACxE,IAAMS,UAAU,SAACJ;eAAeF,aAAaE;;IAC7C,IAAMK,QAAQ;eAAMP;;IACpB,IAAMK,UAAU,SAASA,QAAQO,MAAM,EAAEC,MAAM,EAAEtB,IAAa;QAC5D,qDAAqD;QACrD,IAAI,CAACC,SAASE,IAAI,IAAIF,SAASG,MAAM,IAAI;YACvCkB,OAAOC,MAAM,IAAI,eAAe;YAChC,OAAOd,aAAa,MAAM,MAAMT;QAClC;QAEA,IAAMwB,aAAa,mBAAKH;QACxBG,WAAWC,IAAI,GAAGC,IAAAA,kCAAa,EAACL,OAAOM,IAAI;QAC3CH,WAAWI,KAAK,GAAG,IAAIC,KAAKL,WAAWI,KAAK;QAE5C,OAAQJ,WAAWM,IAAI;YACrB,KAAK;gBACHR,OAAOC,MAAM,IAAI,eAAe;gBAChC,OAAOd,aAAa,MAAM,IAAIsB,mCAAc,CAACP,aAAaxB;YAC5D,KAAK;gBACHsB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWQ,QAAQ,GAAGX,OAAOY,QAAQ;gBACrC,OAAOxB,aAAa,MAAM,IAAIyB,sCAAiB,CAACV,aAAaxB;YAC/D,KAAK;gBACHsB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWQ,QAAQ,GAAGX,OAAOY,QAAQ;gBACrC,OAAOxB,aAAa,MAAM,IAAI0B,8BAAS,CAACX,aAAaxB;YACvD,KAAK;gBACH,OAAOS,aAAa,MAAM,IAAI2B,oBAAS,CAACZ,YAAYF,QAAQrB,SAASE,IAAI,GAAGH;QAChF;QAEAsB,OAAOC,MAAM,IAAI,eAAe;QAChC,OAAOd,aAAa,IAAID,MAAM,AAAC,4BAA2C,OAAhBgB,WAAWM,IAAI,IAAK,MAAM9B;IACtF;IAEAO,QAAQ8B,EAAE,CAAC,SAASvB;IACpBP,QAAQ8B,EAAE,CAAC,SAAStB;IACpBR,QAAQ8B,EAAE,CAAC,UAAUrB;IAErB,2CAA2C;IAC3C,wEAAwE;IACxE,uFAAuF;IACvF,IAAIhB,MAAM;QACRA;IACF,OAAO;QACL,gDAAgD;QAChDO,QAAQgB,MAAM;IAChB;AACF"}
@@ -4,12 +4,9 @@ import fs from 'fs';
4
4
  import oo from 'on-one';
5
5
  let TarFileEntry = class TarFileEntry extends FileEntry {
6
6
  create(dest, options, callback) {
7
- if (typeof options === 'function') {
8
- callback = options;
9
- options = null;
10
- }
7
+ callback = typeof options === 'function' ? options : callback;
8
+ options = typeof options === 'function' ? {} : options || {};
11
9
  if (typeof callback === 'function') {
12
- options = options || {};
13
10
  return FileEntry.prototype.create.call(this, dest, options, (err)=>{
14
11
  callback(err);
15
12
  if (this.lock) {
@@ -18,9 +15,7 @@ let TarFileEntry = class TarFileEntry extends FileEntry {
18
15
  }
19
16
  });
20
17
  }
21
- return new Promise((resolve, reject)=>{
22
- this.create(dest, options, (err, done)=>err ? reject(err) : resolve(done));
23
- });
18
+ return new Promise((resolve, reject)=>this.create(dest, options, (err, done)=>err ? reject(err) : resolve(done)));
24
19
  }
25
20
  _writeFile(fullPath, _options, callback) {
26
21
  if (!this.stream) {
@@ -36,11 +31,17 @@ let TarFileEntry = class TarFileEntry extends FileEntry {
36
31
  try {
37
32
  const writeStream = fs.createWriteStream(fullPath);
38
33
  // Listen for errors on source stream (errors don't propagate through pipe)
39
- stream.on('error', (err)=>{
40
- // Destroy the write stream on source error
34
+ stream.on('error', (streamErr)=>{
35
+ // Destroy the write stream on source error.
36
+ // On Node 0.8, destroy() emits 'close' before 'error'. Since on-one is listening
37
+ // for ['error', 'close', 'finish'], it catches 'close' first, calls our callback,
38
+ // and removes ALL listeners - including the 'error' listener. The subsequent EBADF
39
+ // error then fires with no handler, causing an uncaught exception.
40
+ // Adding a no-op error handler ensures there's always a listener for any error.
41
41
  const ws = writeStream;
42
+ writeStream.on('error', ()=>{});
42
43
  if (typeof ws.destroy === 'function') ws.destroy();
43
- cb(err);
44
+ cb(streamErr);
44
45
  });
45
46
  // Pipe and listen for write stream completion/errors
46
47
  stream.pipe(writeStream);
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/FileEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n if (typeof callback === 'function') {\n options = options || {};\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n\n return new Promise((resolve, reject) => {\n this.create(dest, options as ExtractOptions, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void {\n if (!this.stream) {\n callback(new Error('FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null; // Prevent reuse\n\n // Use once since errors can come from either stream\n const cb = once((err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally\n });\n\n try {\n const writeStream = fs.createWriteStream(fullPath);\n\n // Listen for errors on source stream (errors don't propagate through pipe)\n stream.on('error', (err: Error) => {\n // Destroy the write stream on source error\n const ws = writeStream as fs.WriteStream & { destroy?: () => void };\n if (typeof ws.destroy === 'function') ws.destroy();\n cb(err);\n });\n\n // Pipe and listen for write stream completion/errors\n stream.pipe(writeStream);\n oo(writeStream, ['error', 'close', 'finish'], cb);\n } catch (err) {\n cb(err);\n }\n }\n\n destroy() {\n 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}\n"],"names":["once","FileEntry","waitForAccess","fs","oo","TarFileEntry","create","dest","options","callback","prototype","call","err","lock","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","stream","Error","cb","writeStream","createWriteStream","on","ws","destroy","pipe","resume","attributes","retain"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,SAA8BC,SAAS,EAAmCC,aAAa,QAAQ,wBAAwB;AACvH,OAAOC,QAAQ,KAAK;AACpB,OAAOC,QAAQ,SAAS;AAIT,IAAA,AAAMC,eAAN,MAAMA,qBAAqBJ;IAcxCK,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B,EAA2B;QACpH,IAAI,OAAOD,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACA,IAAI,OAAOC,aAAa,YAAY;YAClCD,UAAUA,WAAW,CAAC;YACtB,OAAOP,UAAUS,SAAS,CAACJ,MAAM,CAACK,IAAI,CAAC,IAAI,EAAEJ,MAAMC,SAAS,CAACI;gBAC3DH,SAASG;gBACT,IAAI,IAAI,CAACC,IAAI,EAAE;oBACb,IAAI,CAACA,IAAI,CAACC,OAAO;oBACjB,IAAI,CAACD,IAAI,GAAG;gBACd;YACF;QACF;QAEA,OAAO,IAAIE,QAAQ,CAACC,SAASC;YAC3B,IAAI,CAACX,MAAM,CAACC,MAAMC,SAA2B,CAACI,KAAaM,OAAoBN,MAAMK,OAAOL,OAAOI,QAAQE;QAC7G;IACF;IAEAC,WAAWC,QAAgB,EAAEC,QAAwB,EAAEZ,QAAyB,EAAQ;QACtF,IAAI,CAAC,IAAI,CAACa,MAAM,EAAE;YAChBb,SAAS,IAAIc,MAAM;YACnB;QACF;QAEA,MAAMD,SAAS,IAAI,CAACA,MAAM;QAC1B,IAAI,CAACA,MAAM,GAAG,MAAM,gBAAgB;QAEpC,oDAAoD;QACpD,MAAME,KAAKxB,KAAK,CAACY;YACfA,MAAMH,SAASG,OAAOV,cAAckB,UAAUX,WAAW,iDAAiD;QAC5G;QAEA,IAAI;YACF,MAAMgB,cAActB,GAAGuB,iBAAiB,CAACN;YAEzC,2EAA2E;YAC3EE,OAAOK,EAAE,CAAC,SAAS,CAACf;gBAClB,2CAA2C;gBAC3C,MAAMgB,KAAKH;gBACX,IAAI,OAAOG,GAAGC,OAAO,KAAK,YAAYD,GAAGC,OAAO;gBAChDL,GAAGZ;YACL;YAEA,qDAAqD;YACrDU,OAAOQ,IAAI,CAACL;YACZrB,GAAGqB,aAAa;gBAAC;gBAAS;gBAAS;aAAS,EAAED;QAChD,EAAE,OAAOZ,KAAK;YACZY,GAAGZ;QACL;IACF;IAEAiB,UAAU;QACR5B,UAAUS,SAAS,CAACmB,OAAO,CAAClB,IAAI,CAAC,IAAI;QACrC,IAAI,IAAI,CAACW,MAAM,EAAE;YACf,IAAI,CAACA,MAAM,CAACS,MAAM,IAAI,eAAe;YACrC,IAAI,CAACT,MAAM,GAAG;QAChB;QACA,IAAI,IAAI,CAACT,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACC,OAAO;YACjB,IAAI,CAACD,IAAI,GAAG;QACd;IACF;IA1EA,YAAYmB,UAA0B,EAAEV,MAA6B,EAAET,IAAU,CAAE;QACjF,KAAK,CAACmB;QACN,IAAI,CAACV,MAAM,GAAGA;QACd,IAAI,CAACT,IAAI,GAAGA;QACZ,IAAI,CAACA,IAAI,CAACoB,MAAM;IAClB;AAsEF;AA/EA,SAAqB5B,0BA+EpB"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/FileEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { type FileAttributes, FileEntry, type Lock, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n }\n\n create(dest: string, callback: NoParamCallback): void;\n create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;\n create(dest: string, options?: ExtractOptions): Promise<boolean>;\n create(dest: string, options?: ExtractOptions | NoParamCallback, callback?: NoParamCallback): void | Promise<boolean> {\n callback = typeof options === 'function' ? options : callback;\n options = typeof options === 'function' ? {} : ((options || {}) as ExtractOptions);\n\n if (typeof callback === 'function') {\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n\n return new Promise((resolve, reject) => this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done))));\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void {\n if (!this.stream) {\n callback(new Error('FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null; // Prevent reuse\n\n // Use once since errors can come from either stream\n const cb = once((err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally\n });\n\n try {\n const writeStream = fs.createWriteStream(fullPath);\n\n // Listen for errors on source stream (errors don't propagate through pipe)\n stream.on('error', (streamErr: Error) => {\n // Destroy the write stream on source error.\n // On Node 0.8, destroy() emits 'close' before 'error'. Since on-one is listening\n // for ['error', 'close', 'finish'], it catches 'close' first, calls our callback,\n // and removes ALL listeners - including the 'error' listener. The subsequent EBADF\n // error then fires with no handler, causing an uncaught exception.\n // Adding a no-op error handler ensures there's always a listener for any error.\n const ws = writeStream as fs.WriteStream & { destroy?: () => void };\n writeStream.on('error', () => {});\n if (typeof ws.destroy === 'function') ws.destroy();\n cb(streamErr);\n });\n\n // Pipe and listen for write stream completion/errors\n stream.pipe(writeStream);\n oo(writeStream, ['error', 'close', 'finish'], cb);\n } catch (err) {\n cb(err);\n }\n }\n\n destroy() {\n 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}\n"],"names":["once","FileEntry","waitForAccess","fs","oo","TarFileEntry","create","dest","options","callback","prototype","call","err","lock","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","stream","Error","cb","writeStream","createWriteStream","on","streamErr","ws","destroy","pipe","resume","attributes","retain"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,SAA8BC,SAAS,EAAmCC,aAAa,QAAQ,wBAAwB;AACvH,OAAOC,QAAQ,KAAK;AACpB,OAAOC,QAAQ,SAAS;AAIT,IAAA,AAAMC,eAAN,MAAMA,qBAAqBJ;IAcxCK,OAAOC,IAAY,EAAEC,OAA0C,EAAEC,QAA0B,EAA2B;QACpHA,WAAW,OAAOD,YAAY,aAAaA,UAAUC;QACrDD,UAAU,OAAOA,YAAY,aAAa,CAAC,IAAMA,WAAW,CAAC;QAE7D,IAAI,OAAOC,aAAa,YAAY;YAClC,OAAOR,UAAUS,SAAS,CAACJ,MAAM,CAACK,IAAI,CAAC,IAAI,EAAEJ,MAAMC,SAAS,CAACI;gBAC3DH,SAASG;gBACT,IAAI,IAAI,CAACC,IAAI,EAAE;oBACb,IAAI,CAACA,IAAI,CAACC,OAAO;oBACjB,IAAI,CAACD,IAAI,GAAG;gBACd;YACF;QACF;QAEA,OAAO,IAAIE,QAAQ,CAACC,SAASC,SAAW,IAAI,CAACX,MAAM,CAACC,MAAMC,SAAS,CAACI,KAAaM,OAAoBN,MAAMK,OAAOL,OAAOI,QAAQE;IACnI;IAEAC,WAAWC,QAAgB,EAAEC,QAAwB,EAAEZ,QAAyB,EAAQ;QACtF,IAAI,CAAC,IAAI,CAACa,MAAM,EAAE;YAChBb,SAAS,IAAIc,MAAM;YACnB;QACF;QAEA,MAAMD,SAAS,IAAI,CAACA,MAAM;QAC1B,IAAI,CAACA,MAAM,GAAG,MAAM,gBAAgB;QAEpC,oDAAoD;QACpD,MAAME,KAAKxB,KAAK,CAACY;YACfA,MAAMH,SAASG,OAAOV,cAAckB,UAAUX,WAAW,iDAAiD;QAC5G;QAEA,IAAI;YACF,MAAMgB,cAActB,GAAGuB,iBAAiB,CAACN;YAEzC,2EAA2E;YAC3EE,OAAOK,EAAE,CAAC,SAAS,CAACC;gBAClB,4CAA4C;gBAC5C,iFAAiF;gBACjF,kFAAkF;gBAClF,mFAAmF;gBACnF,mEAAmE;gBACnE,gFAAgF;gBAChF,MAAMC,KAAKJ;gBACXA,YAAYE,EAAE,CAAC,SAAS,KAAO;gBAC/B,IAAI,OAAOE,GAAGC,OAAO,KAAK,YAAYD,GAAGC,OAAO;gBAChDN,GAAGI;YACL;YAEA,qDAAqD;YACrDN,OAAOS,IAAI,CAACN;YACZrB,GAAGqB,aAAa;gBAAC;gBAAS;gBAAS;aAAS,EAAED;QAChD,EAAE,OAAOZ,KAAK;YACZY,GAAGZ;QACL;IACF;IAEAkB,UAAU;QACR7B,UAAUS,SAAS,CAACoB,OAAO,CAACnB,IAAI,CAAC,IAAI;QACrC,IAAI,IAAI,CAACW,MAAM,EAAE;YACf,IAAI,CAACA,MAAM,CAACU,MAAM,IAAI,eAAe;YACrC,IAAI,CAACV,MAAM,GAAG;QAChB;QACA,IAAI,IAAI,CAACT,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACC,OAAO;YACjB,IAAI,CAACD,IAAI,GAAG;QACd;IACF;IA5EA,YAAYoB,UAA0B,EAAEX,MAA6B,EAAET,IAAU,CAAE;QACjF,KAAK,CAACoB;QACN,IAAI,CAACX,MAAM,GAAGA;QACd,IAAI,CAACT,IAAI,GAAGA;QACZ,IAAI,CAACA,IAAI,CAACqB,MAAM;IAClB;AAwEF;AAjFA,SAAqB7B,0BAiFpB"}
@@ -17,8 +17,8 @@ export default function nextEntry(next, iterator, callback) {
17
17
  extract.removeListener('finish', onEnd);
18
18
  // keep processing
19
19
  if (entry) iterator.push(nextEntry.bind(null, next));
20
- // Defer the callback invocation to ensure proper async behavior with the BaseIterator
21
- setTimeout(()=>{
20
+ // Avoid Zalgo: ensure callback is always async even when entry is available synchronously
21
+ process.nextTick(()=>{
22
22
  err ? callback(err) : callback(null, entry ? {
23
23
  done: false,
24
24
  value: entry
@@ -26,7 +26,7 @@ export default function nextEntry(next, iterator, callback) {
26
26
  done: true,
27
27
  value: null
28
28
  });
29
- }, 0);
29
+ });
30
30
  });
31
31
  // Use nextCallback for all events to ensure once() wrapper is respected
32
32
  const onError = (err)=>nextCallback(err);
@@ -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, normalizePath, SymbolicLinkEntry } from 'extract-base-iterator';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\nexport type TarNext = () => void;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => void;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): void {\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 // Defer the callback invocation to ensure proper async behavior with the BaseIterator\n setTimeout(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n }, 0);\n }) as NextCallback;\n\n // Use nextCallback for all events to ensure once() wrapper is respected\n const onError = (err: Error) => nextCallback(err);\n const onEnd = () => nextCallback();\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 = normalizePath(header.name);\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","normalizePath","SymbolicLinkEntry","FileEntry","nextEntry","next","iterator","callback","lock","isDone","done","value","extract","Error","nextCallback","err","entry","removeListener","onEntry","onError","onEnd","push","bind","setTimeout","header","stream","resume","attributes","path","name","mtime","Date","type","linkpath","linkname","on"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,SAASC,cAAc,EAAEC,SAAS,EAAEC,aAAa,EAAEC,iBAAiB,QAAQ,wBAAwB;AACpG,OAAOC,eAAe,iBAAiB;AAQvC,eAAe,SAASC,UAAUC,IAAa,EAAEC,QAAkB,EAAEC,QAAuB;IAC1F,8CAA8C;IAC9C,IAAI,CAACD,SAASE,IAAI,IAAIF,SAASG,MAAM,IAAI;QACvC,OAAOF,SAAS,MAAM;YAAEG,MAAM;YAAMC,OAAO;QAAK;IAClD;IAEA,MAAMC,UAAUN,SAASM,OAAO;IAChC,IAAI,CAACA,SAAS,OAAOL,SAAS,IAAIM,MAAM;IAExC,MAAMC,eAAehB,KAAK,CAACiB,KAAaC,OAAeX;QACrDO,QA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Aa,MAAM,IAAIX,UAAUwB,YAAYF,QAAQnB,SAASE,IAAI,GAAGH;QAChF;QAEAoB,OAAOC,MAAM,IAAI,eAAe;QAChC,OAAOZ,aAAa,IAAID,MAAM,CAAC,yBAAyB,EAAEc,WAAWK,IAAI,EAAE,GAAG,MAAM3B;IACtF;IAEAO,QAAQuB,EAAE,CAAC,SAASjB;IACpBN,QAAQuB,EAAE,CAAC,SAAShB;IACpBP,QAAQuB,EAAE,CAAC,UAAUf;IAErB,2CAA2C;IAC3C,wEAAwE;IACxE,uFAAuF;IACvF,IAAIf,MAAM;QACRA;IACF,OAAO;QACL,gDAAgD;QAChDO,QAAQc,MAAM;IAChB;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/nextEntry.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport { DirectoryEntry, LinkEntry, normalizePath, SymbolicLinkEntry } from 'extract-base-iterator';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\nexport type TarNext = () => void;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => void;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): void {\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 // Avoid Zalgo: ensure callback is always async even when entry is available synchronously\n process.nextTick(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n });\n }) as NextCallback;\n\n // Use nextCallback for all events to ensure once() wrapper is respected\n const onError = (err: Error) => nextCallback(err);\n const onEnd = () => nextCallback();\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 = normalizePath(header.name);\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","normalizePath","SymbolicLinkEntry","FileEntry","nextEntry","next","iterator","callback","lock","isDone","done","value","extract","Error","nextCallback","err","entry","removeListener","onEntry","onError","onEnd","push","bind","process","nextTick","header","stream","resume","attributes","path","name","mtime","Date","type","linkpath","linkname","on"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,SAASC,cAAc,EAAEC,SAAS,EAAEC,aAAa,EAAEC,iBAAiB,QAAQ,wBAAwB;AACpG,OAAOC,eAAe,iBAAiB;AAQvC,eAAe,SAASC,UAAUC,IAAa,EAAEC,QAAkB,EAAEC,QAAuB;IAC1F,8CAA8C;IAC9C,IAAI,CAACD,SAASE,IAAI,IAAIF,SAASG,MAAM,IAAI;QACvC,OAAOF,SAAS,MAAM;YAAEG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B0B,aAAavB;YAC/D,KAAK;gBACHqB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWM,QAAQ,GAAGT,OAAOU,QAAQ;gBACrC,OAAOrB,aAAa,MAAM,IAAId,UAAU4B,aAAavB;YACvD,KAAK;gBACH,OAAOS,aAAa,MAAM,IAAIX,UAAUyB,YAAYF,QAAQpB,SAASE,IAAI,GAAGH;QAChF;QAEAqB,OAAOC,MAAM,IAAI,eAAe;QAChC,OAAOb,aAAa,IAAID,MAAM,CAAC,yBAAyB,EAAEe,WAAWK,IAAI,EAAE,GAAG,MAAM5B;IACtF;IAEAO,QAAQwB,EAAE,CAAC,SAASlB;IACpBN,QAAQwB,EAAE,CAAC,SAASjB;IACpBP,QAAQwB,EAAE,CAAC,UAAUhB;IAErB,2CAA2C;IAC3C,wEAAwE;IACxE,uFAAuF;IACvF,IAAIf,MAAM;QACRA;IACF,OAAO;QACL,gDAAgD;QAChDO,QAAQe,MAAM;IAChB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tar-iterator",
3
- "version": "3.3.0",
3
+ "version": "3.3.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",