tar-iterator 3.1.10 → 3.2.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.
Files changed (48) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/FileEntry.d.cts +1 -2
  3. package/dist/cjs/FileEntry.d.ts +1 -2
  4. package/dist/cjs/FileEntry.js +19 -7
  5. package/dist/cjs/FileEntry.js.map +1 -1
  6. package/dist/cjs/TarIterator.d.cts +5 -6
  7. package/dist/cjs/TarIterator.d.ts +5 -6
  8. package/dist/cjs/TarIterator.js +57 -10
  9. package/dist/cjs/TarIterator.js.map +1 -1
  10. package/dist/cjs/nextEntry.js +5 -6
  11. package/dist/cjs/nextEntry.js.map +1 -1
  12. package/dist/cjs/tar/Extensions.d.cts +57 -0
  13. package/dist/cjs/tar/Extensions.d.ts +57 -0
  14. package/dist/cjs/tar/Extensions.js +136 -0
  15. package/dist/cjs/tar/Extensions.js.map +1 -0
  16. package/dist/cjs/tar/TarExtract.d.cts +31 -24
  17. package/dist/cjs/tar/TarExtract.d.ts +31 -24
  18. package/dist/cjs/tar/TarExtract.js +52 -111
  19. package/dist/cjs/tar/TarExtract.js.map +1 -1
  20. package/dist/cjs/types.d.cts +4 -3
  21. package/dist/cjs/types.d.ts +4 -3
  22. package/dist/cjs/types.js +3 -0
  23. package/dist/cjs/types.js.map +1 -1
  24. package/dist/esm/FileEntry.d.ts +1 -2
  25. package/dist/esm/FileEntry.js +19 -7
  26. package/dist/esm/FileEntry.js.map +1 -1
  27. package/dist/esm/TarIterator.d.ts +5 -6
  28. package/dist/esm/TarIterator.js +13 -9
  29. package/dist/esm/TarIterator.js.map +1 -1
  30. package/dist/esm/nextEntry.js +5 -8
  31. package/dist/esm/nextEntry.js.map +1 -1
  32. package/dist/esm/tar/Extensions.d.ts +57 -0
  33. package/dist/esm/tar/Extensions.js +124 -0
  34. package/dist/esm/tar/Extensions.js.map +1 -0
  35. package/dist/esm/tar/TarExtract.d.ts +31 -24
  36. package/dist/esm/tar/TarExtract.js +54 -111
  37. package/dist/esm/tar/TarExtract.js.map +1 -1
  38. package/dist/esm/types.d.ts +4 -3
  39. package/dist/esm/types.js +1 -1
  40. package/dist/esm/types.js.map +1 -1
  41. package/package.json +16 -16
  42. package/dist/cjs/lib/Lock.d.cts +0 -13
  43. package/dist/cjs/lib/Lock.d.ts +0 -13
  44. package/dist/cjs/lib/Lock.js +0 -62
  45. package/dist/cjs/lib/Lock.js.map +0 -1
  46. package/dist/esm/lib/Lock.d.ts +0 -13
  47. package/dist/esm/lib/Lock.js +0 -38
  48. package/dist/esm/lib/Lock.js.map +0 -1
@@ -1,5 +1,4 @@
1
- import { type FileAttributes, FileEntry, type NoParamCallback } from 'extract-base-iterator';
2
- import type Lock from './lib/Lock.js';
1
+ import { type FileAttributes, FileEntry, type Lock, type NoParamCallback } from 'extract-base-iterator';
3
2
  import type { ExtractOptions } from './types.js';
4
3
  export default class TarFileEntry extends FileEntry {
5
4
  private lock;
@@ -1,3 +1,4 @@
1
+ import once from 'call-once-fn';
1
2
  import { FileEntry, waitForAccess } from 'extract-base-iterator';
2
3
  import fs from 'fs';
3
4
  import oo from 'on-one';
@@ -27,19 +28,30 @@ let TarFileEntry = class TarFileEntry extends FileEntry {
27
28
  return;
28
29
  }
29
30
  const stream = this.stream;
30
- this.stream = null;
31
+ this.stream = null; // Prevent reuse
32
+ // Use once since errors can come from either stream
33
+ const cb = once((err)=>{
34
+ err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally
35
+ });
31
36
  try {
32
- const res = stream.pipe(fs.createWriteStream(fullPath));
33
- oo(res, [
37
+ const writeStream = fs.createWriteStream(fullPath);
38
+ // 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
41
+ const ws = writeStream;
42
+ if (typeof ws.destroy === 'function') ws.destroy();
43
+ cb(err);
44
+ });
45
+ // Pipe and listen for write stream completion/errors
46
+ stream.pipe(writeStream);
47
+ oo(writeStream, [
34
48
  'error',
35
49
  'end',
36
50
  'close',
37
51
  'finish'
38
- ], (err)=>{
39
- err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally
40
- });
52
+ ], cb);
41
53
  } catch (err) {
42
- callback(err);
54
+ cb(err);
43
55
  }
44
56
  }
45
57
  destroy() {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/FileEntry.ts"],"sourcesContent":["import { type FileAttributes, FileEntry, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\n\nimport type Lock from './lib/Lock.ts';\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, options: ExtractOptions | NoParamCallback, callback: NoParamCallback): undefined | 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, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): undefined {\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;\n try {\n const res = stream.pipe(fs.createWriteStream(fullPath));\n oo(res, ['error', 'end', 'close', 'finish'], (err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally\n });\n } catch (err) {\n callback(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":["FileEntry","waitForAccess","fs","oo","TarFileEntry","create","dest","options","callback","prototype","call","err","lock","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","stream","Error","res","pipe","createWriteStream","destroy","resume","attributes","retain"],"mappings":"AAAA,SAA8BA,SAAS,EAAwBC,aAAa,QAAQ,wBAAwB;AAC5G,OAAOC,QAAQ,KAAK;AACpB,OAAOC,QAAQ,SAAS;AAKT,IAAA,AAAMC,eAAN,MAAMA,qBAAqBJ;IAWxCK,OAAOC,IAAY,EAAEC,OAAyC,EAAEC,QAAyB,EAAgC;QACvH,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,SAAS,CAACI,KAAaM,OAAoBN,MAAMK,OAAOL,OAAOI,QAAQE;QAC3F;IACF;IAEAC,WAAWC,QAAgB,EAAEC,QAAwB,EAAEZ,QAAyB,EAAa;QAC3F,IAAI,CAAC,IAAI,CAACa,MAAM,EAAE;YAChBb,SAAS,IAAIc,MAAM;YACnB;QACF;QAEA,MAAMD,SAAS,IAAI,CAACA,MAAM;QAC1B,IAAI,CAACA,MAAM,GAAG;QACd,IAAI;YACF,MAAME,MAAMF,OAAOG,IAAI,CAACtB,GAAGuB,iBAAiB,CAACN;YAC7ChB,GAAGoB,KAAK;gBAAC;gBAAS;gBAAO;gBAAS;aAAS,EAAE,CAACZ;gBAC5CA,MAAMH,SAASG,OAAOV,cAAckB,UAAUX,WAAW,iDAAiD;YAC5G;QACF,EAAE,OAAOG,KAAK;YACZH,SAASG;QACX;IACF;IAEAe,UAAU;QACR1B,UAAUS,SAAS,CAACiB,OAAO,CAAChB,IAAI,CAAC,IAAI;QACrC,IAAI,IAAI,CAACW,MAAM,EAAE;YACf,IAAI,CAACA,MAAM,CAACM,MAAM,IAAI,eAAe;YACrC,IAAI,CAACN,MAAM,GAAG;QAChB;QACA,IAAI,IAAI,CAACT,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACC,OAAO;YACjB,IAAI,CAACD,IAAI,GAAG;QACd;IACF;IAxDA,YAAYgB,UAA0B,EAAEP,MAA6B,EAAET,IAAU,CAAE;QACjF,KAAK,CAACgB;QACN,IAAI,CAACP,MAAM,GAAGA;QACd,IAAI,CAACT,IAAI,GAAGA;QACZ,IAAI,CAACA,IAAI,CAACiB,MAAM;IAClB;AAoDF;AA7DA,SAAqBzB,0BA6DpB"}
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, options: ExtractOptions | NoParamCallback, callback: NoParamCallback): undefined | 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, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): undefined {\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', 'end', '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;IAWxCK,OAAOC,IAAY,EAAEC,OAAyC,EAAEC,QAAyB,EAAgC;QACvH,IAAI,OAAOD,YAAY,YAAY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B,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;IAvEA,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;AAmEF;AA5EA,SAAqB5B,0BA4EpB"}
@@ -1,12 +1,11 @@
1
- import BaseIterator from 'extract-base-iterator';
2
- import Lock from './lib/Lock.js';
1
+ import BaseIterator, { Lock } from 'extract-base-iterator';
3
2
  import TarExtract from './tar/TarExtract.js';
4
- import type { ExtractOptions } from './types.js';
5
- export default class TarIterator extends BaseIterator {
3
+ import type { Entry, ExtractOptions } from './types.js';
4
+ export default class TarIterator extends BaseIterator<Entry> {
6
5
  /** @internal @hidden */
7
- lock: Lock;
6
+ lock: Lock | null;
8
7
  /** @internal @hidden */
9
- extract: TarExtract;
8
+ extract: TarExtract | null;
10
9
  constructor(source: string | NodeJS.ReadableStream, options?: ExtractOptions);
11
10
  end(err?: Error): void;
12
11
  }
@@ -1,7 +1,6 @@
1
1
  import once from 'call-once-fn';
2
- import BaseIterator from 'extract-base-iterator';
2
+ import BaseIterator, { Lock } from 'extract-base-iterator';
3
3
  import fs from 'fs';
4
- import Lock from './lib/Lock.js';
5
4
  import nextEntry from './nextEntry.js';
6
5
  import TarExtract from './tar/TarExtract.js';
7
6
  let TarIterator = class TarIterator extends BaseIterator {
@@ -17,7 +16,7 @@ let TarIterator = class TarIterator extends BaseIterator {
17
16
  constructor(source, options = {}){
18
17
  super(options);
19
18
  this.lock = new Lock();
20
- this.lock.iterator = this;
19
+ this.lock.onDestroy = (err)=>BaseIterator.prototype.end.call(this, err);
21
20
  let cancelled = false;
22
21
  const setup = ()=>{
23
22
  cancelled = true;
@@ -27,28 +26,33 @@ let TarIterator = class TarIterator extends BaseIterator {
27
26
  // Note: options passed here are ExtractOptions (strip, force, etc.)
28
27
  // TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different
29
28
  this.extract = new TarExtract();
30
- this.lock.extract = this.extract;
31
29
  const pipe = (cb)=>{
32
30
  try {
33
31
  if (typeof source === 'string') source = fs.createReadStream(source);
34
32
  } catch (err) {
35
33
  cb(err);
36
34
  }
37
- // Store source stream in lock for cleanup
38
- this.lock.sourceStream = source;
35
+ // Register cleanup for source stream
36
+ const stream = source;
37
+ this.lock.registerCleanup(()=>{
38
+ const s = stream;
39
+ if (typeof s.destroy === 'function') s.destroy();
40
+ });
39
41
  const end = once(cb);
40
42
  const self = this;
43
+ let firstData = true;
41
44
  source.on('data', function onData(chunk) {
42
45
  try {
43
46
  if (self.extract) self.extract.write(chunk);
47
+ if (firstData) {
48
+ firstData = false;
49
+ end();
50
+ }
44
51
  } catch (err) {
45
52
  // Handle synchronous errors from TarExtract (e.g., invalid format)
46
53
  end(err);
47
54
  }
48
55
  });
49
- source.on('data', function onFirstData() {
50
- end();
51
- });
52
56
  source.on('error', end);
53
57
  source.on('end', function onEnd() {
54
58
  if (self.extract) self.extract.end();
@@ -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 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;AAI9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AiCY,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"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/TarIterator.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport BaseIterator, { Lock } from 'extract-base-iterator';\nimport fs from 'fs';\n\nimport nextEntry from './nextEntry.ts';\nimport TarExtract from './tar/TarExtract.ts';\n\nimport type { Entry, ExtractOptions } from './types.ts';\n\nexport default class TarIterator extends BaseIterator<Entry> {\n /** @internal @hidden */\n lock: Lock | null;\n /** @internal @hidden */\n extract: TarExtract | null;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.onDestroy = (err) => BaseIterator.prototype.end.call(this, err);\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 // Register cleanup for source stream\n const stream = source as NodeJS.ReadableStream;\n this.lock.registerCleanup(() => {\n const s = stream as NodeJS.ReadableStream & { destroy?: () => void };\n if (typeof s.destroy === 'function') s.destroy();\n });\n\n const end = once(cb);\n const self = this;\n let firstData = true;\n (source as NodeJS.ReadableStream).on('data', function onData(chunk) {\n try {\n if (self.extract) self.extract.write(chunk);\n if (firstData) {\n firstData = false;\n end();\n }\n } catch (err) {\n // Handle synchronous errors from TarExtract (e.g., invalid format)\n end(err);\n }\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","Lock","fs","nextEntry","TarExtract","TarIterator","end","err","lock","release","extract","source","options","onDestroy","prototype","call","cancelled","setup","processing","push","pipe","cb","createReadStream","stream","registerCleanup","s","destroy","self","firstData","on","onData","chunk","write","onEnd","remove","done","bind"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,OAAOC,gBAAgBC,IAAI,QAAQ,wBAAwB;AAC3D,OAAOC,QAAQ,KAAK;AAEpB,OAAOC,eAAe,iBAAiB;AACvC,OAAOC,gBAAgB,sBAAsB;AAI9B,IAAA,AAAMC,cAAN,MAAMA,oBAAoBL;IA+DvCM,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;IAjEA,YAAYC,MAAsC,EAAEC,UAA0B,CAAC,CAAC,CAAE;QAChF,KAAK,CAACA;QACN,IAAI,CAACJ,IAAI,GAAG,IAAIP;QAChB,IAAI,CAACO,IAAI,CAACK,SAAS,GAAG,CAACN,MAAQP,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AAC,MAAM;QACvD;IACF;AAWF;AAxEA,SAAqB/B,yBAwEpB"}
@@ -1,11 +1,8 @@
1
1
  import once from 'call-once-fn';
2
- import { DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';
3
- import path from 'path';
2
+ import { DirectoryEntry, LinkEntry, normalizePath, SymbolicLinkEntry } from 'extract-base-iterator';
4
3
  import FileEntry from './FileEntry.js';
5
- // Node 0.8 compatible setImmediate (setImmediate was added in Node 0.10)
6
- const _setImmediate = typeof setImmediate === 'function' ? setImmediate : typeof process !== 'undefined' && typeof process.nextTick === 'function' ? process.nextTick : function setImmediateFallback(fn) {
7
- setTimeout(fn, 0);
8
- };
4
+ // setImmediate is preferred (Node 0.10+), falls back to setTimeout for Node 0.8
5
+ const defer = typeof setImmediate === 'function' ? setImmediate : (fn)=>setTimeout(fn, 0);
9
6
  export default function nextEntry(next, iterator, callback) {
10
7
  // Guard: bail early if iterator already ended
11
8
  if (!iterator.lock || iterator.isDone()) {
@@ -24,7 +21,7 @@ export default function nextEntry(next, iterator, callback) {
24
21
  if (entry) iterator.push(nextEntry.bind(null, next));
25
22
  // Use setImmediate to defer the callback invocation
26
23
  // This ensures proper async behavior with the BaseIterator
27
- _setImmediate(()=>{
24
+ defer(()=>{
28
25
  err ? callback(err) : callback(null, entry ? {
29
26
  done: false,
30
27
  value: entry
@@ -46,7 +43,7 @@ export default function nextEntry(next, iterator, callback) {
46
43
  const attributes = {
47
44
  ...header
48
45
  };
49
- attributes.path = header.name.split(path.sep).filter(Boolean).join(path.sep);
46
+ attributes.path = normalizePath(header.name);
50
47
  attributes.mtime = new Date(attributes.mtime);
51
48
  switch(attributes.type){
52
49
  case 'directory':
@@ -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 // 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 // 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 = 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":"AAAA,OAAOA,UAAU,eAAe;AAChC,SAASC,cAAc,EAAEC,SAAS,EAAEC,iBAAiB,QAAQ,wBAAwB;AACrF,OAAOC,UAAU,OAAO;AACxB,OAAOC,eAAe,iBAAiB;AAKvC,yEAAyE;AACzE,MAAMC,gBACJ,OAAOC,iBAAiB,aACpBA,eACA,OAAOC,YAAY,eAAe,OAAOA,QAAQC,QAAQ,KAAK,aAC5DD,QAAQC,QAAQ,GAChB,SAASC,qBAAqBC,EAAc;IAC1CC,WAAWD,IAAI;AACjB;AAKR,eAAe,SAASE,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,MAA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AAI,eAAe;gBAChCC,WAAWU,QAAQ,GAAGb,OAAOc,QAAQ;gBACrC,OAAOvB,aAAa,MAAM,IAAIrB,UAAUiC,aAAarB;YACvD,KAAK;gBACH,OAAOS,aAAa,MAAM,IAAIlB,UAAU8B,YAAYF,QAAQlB,SAASE,IAAI,GAAGH;QAChF;QAEAmB,OAAOC,MAAM,IAAI,eAAe;QAChC,OAAOX,aAAa,IAAID,MAAM,CAAC,yBAAyB,EAAEa,WAAWS,IAAI,EAAE,GAAG,MAAM9B;IACtF;IAEAO,QAAQ0B,EAAE,CAAC,SAASpB;IACpBN,QAAQ0B,EAAE,CAAC,SAASnB;IACpBP,QAAQ0B,EAAE,CAAC,UAAUlB;IAErB,2CAA2C;IAC3C,wEAAwE;IACxE,uFAAuF;IACvF,IAAIf,MAAM;QACRA;IACF,OAAO;QACL,gDAAgD;QAChDO,QAAQa,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\n// setImmediate is preferred (Node 0.10+), falls back to setTimeout for Node 0.8\nconst defer = typeof setImmediate === 'function' ? setImmediate : (fn: () => void) => setTimeout(fn, 0);\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 defer(() => {\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","defer","setImmediate","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","path","name","mtime","Date","type","linkpath","linkname","on"],"mappings":"AAAA,OAAOA,UAAU,eA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QAC/BG,WAAWC,IAAI,GAAG9B,cAAc0B,OAAOK,IAAI;QAC3CF,WAAWG,KAAK,GAAG,IAAIC,KAAKJ,WAAWG,KAAK;QAE5C,OAAQH,WAAWK,IAAI;YACrB,KAAK;gBACHP,OAAOC,MAAM,IAAI,eAAe;gBAChC,OAAOX,aAAa,MAAM,IAAInB,eAAe+B,aAAarB;YAC5D,KAAK;gBACHmB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWM,QAAQ,GAAGT,OAAOU,QAAQ;gBACrC,OAAOnB,aAAa,MAAM,IAAIhB,kBAAkB4B,aAAarB;YAC/D,KAAK;gBACHmB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWM,QAAQ,GAAGT,OAAOU,QAAQ;gBACrC,OAAOnB,aAAa,MAAM,IAAIlB,UAAU8B,aAAarB;YACvD,KAAK;gBACH,OAAOS,aAAa,MAAM,IAAIf,UAAU2B,YAAYF,QAAQlB,SAASE,IAAI,GAAGH;QAChF;QAEAmB,OAAOC,MAAM,IAAI,eAAe;QAChC,OAAOX,aAAa,IAAID,MAAM,CAAC,yBAAyB,EAAEa,WAAWK,IAAI,EAAE,GAAG,MAAM1B;IACtF;IAEAO,QAAQsB,EAAE,CAAC,SAAShB;IACpBN,QAAQsB,EAAE,CAAC,SAASf;IACpBP,QAAQsB,EAAE,CAAC,UAAUd;IAErB,2CAA2C;IAC3C,wEAAwE;IACxE,uFAAuF;IACvF,IAAIf,MAAM;QACRA;IACF,OAAO;QACL,gDAAgD;QAChDO,QAAQa,MAAM;IAChB;AACF"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Extensions - GNU/PAX extension handling for TAR
3
+ *
4
+ * Manages state and decoding for:
5
+ * - GNU LongPath (type 'L') - paths > 100 chars
6
+ * - GNU LongLink (type 'K') - symlink targets > 100 chars
7
+ * - PAX Headers (type 'x') - extended attributes per-entry
8
+ * - PAX Global Headers (type 'g') - extended attributes for all entries
9
+ */
10
+ import { type TarHeader } from './headers.js';
11
+ /**
12
+ * Extension state for accumulating extension data across chunks
13
+ */
14
+ export interface ExtensionState {
15
+ /** GNU long path for next entry */
16
+ gnuLongPath: string | null;
17
+ /** GNU long link (symlink target) for next entry */
18
+ gnuLongLink: string | null;
19
+ /** PAX header for next entry */
20
+ paxHeader: Record<string, string> | null;
21
+ /** PAX global headers (apply to all subsequent entries) */
22
+ paxGlobal: Record<string, string>;
23
+ /** Accumulated extension data chunks */
24
+ extensionData: Buffer[];
25
+ /** Bytes remaining to read for current extension */
26
+ extensionRemaining: number;
27
+ }
28
+ /**
29
+ * Create a fresh extension state
30
+ */
31
+ export declare function createExtensionState(): ExtensionState;
32
+ /**
33
+ * Finalize extension data and update state
34
+ *
35
+ * @param state Extension state to update
36
+ * @param currentState Parser state (STATE_GNU_LONG_PATH, etc.)
37
+ * @param header Current header (for PAX global detection)
38
+ * @param encoding Filename encoding
39
+ */
40
+ export declare function finalizeExtension(state: ExtensionState, currentState: number, header: {
41
+ type: string;
42
+ } | null, encoding: BufferEncoding): void;
43
+ /**
44
+ * Apply pending GNU/PAX extensions to a header
45
+ *
46
+ * @param header Header to modify
47
+ * @param state Extension state (will be partially cleared)
48
+ */
49
+ export declare function applyExtensions(header: TarHeader, state: ExtensionState): void;
50
+ /**
51
+ * Apply PAX attributes to header
52
+ */
53
+ export declare function applyPaxToHeader(header: TarHeader, pax: Record<string, string>): void;
54
+ /**
55
+ * Concatenate buffers (Node 0.8 compatible)
56
+ */
57
+ export declare function concatBuffers(buffers: Buffer[]): Buffer;
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Extensions - GNU/PAX extension handling for TAR
3
+ *
4
+ * Manages state and decoding for:
5
+ * - GNU LongPath (type 'L') - paths > 100 chars
6
+ * - GNU LongLink (type 'K') - symlink targets > 100 chars
7
+ * - PAX Headers (type 'x') - extended attributes per-entry
8
+ * - PAX Global Headers (type 'g') - extended attributes for all entries
9
+ */ import { allocBufferUnsafe } from 'extract-base-iterator';
10
+ import { decodeLongPath, decodePax } from './headers.js';
11
+ /**
12
+ * Create a fresh extension state
13
+ */ export function createExtensionState() {
14
+ return {
15
+ gnuLongPath: null,
16
+ gnuLongLink: null,
17
+ paxHeader: null,
18
+ paxGlobal: {},
19
+ extensionData: [],
20
+ extensionRemaining: 0
21
+ };
22
+ }
23
+ /**
24
+ * Finalize extension data and update state
25
+ *
26
+ * @param state Extension state to update
27
+ * @param currentState Parser state (STATE_GNU_LONG_PATH, etc.)
28
+ * @param header Current header (for PAX global detection)
29
+ * @param encoding Filename encoding
30
+ */ export function finalizeExtension(state, currentState, header, encoding) {
31
+ // Import state constants
32
+ const STATE_GNU_LONG_PATH = 4;
33
+ const STATE_GNU_LONG_LINK = 5;
34
+ const STATE_PAX_HEADER = 6;
35
+ // Concatenate all collected data
36
+ const combined = concatBuffers(state.extensionData);
37
+ state.extensionData = [];
38
+ switch(currentState){
39
+ case STATE_GNU_LONG_PATH:
40
+ state.gnuLongPath = decodeLongPath(combined, encoding);
41
+ break;
42
+ case STATE_GNU_LONG_LINK:
43
+ state.gnuLongLink = decodeLongPath(combined, encoding);
44
+ break;
45
+ case STATE_PAX_HEADER:
46
+ // Check if this was a global header
47
+ if (header && header.type === 'pax-global-header') {
48
+ const global = decodePax(combined);
49
+ // Merge into global (don't replace, merge)
50
+ for(const key in global){
51
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: ES2021 compatibility
52
+ if (global.hasOwnProperty(key)) {
53
+ state.paxGlobal[key] = global[key];
54
+ }
55
+ }
56
+ } else {
57
+ state.paxHeader = decodePax(combined);
58
+ }
59
+ break;
60
+ }
61
+ }
62
+ /**
63
+ * Apply pending GNU/PAX extensions to a header
64
+ *
65
+ * @param header Header to modify
66
+ * @param state Extension state (will be partially cleared)
67
+ */ export function applyExtensions(header, state) {
68
+ // Apply PAX global header first
69
+ if (state.paxGlobal) {
70
+ applyPaxToHeader(header, state.paxGlobal);
71
+ }
72
+ // Apply PAX header (per-entry, overrides global)
73
+ if (state.paxHeader) {
74
+ applyPaxToHeader(header, state.paxHeader);
75
+ header.pax = state.paxHeader;
76
+ state.paxHeader = null;
77
+ }
78
+ // Apply GNU long path (overrides PAX path)
79
+ if (state.gnuLongPath !== null) {
80
+ header.name = state.gnuLongPath;
81
+ state.gnuLongPath = null;
82
+ }
83
+ // Apply GNU long link (overrides PAX linkpath)
84
+ if (state.gnuLongLink !== null) {
85
+ header.linkname = state.gnuLongLink;
86
+ state.gnuLongLink = null;
87
+ }
88
+ // Handle old tar versions that use trailing / to indicate directories
89
+ // This check is done AFTER extensions are applied so we use the final
90
+ // resolved name (GNU long path or PAX path), not the truncated name field.
91
+ if (header.type === 'file' && header.name && header.name[header.name.length - 1] === '/') {
92
+ header.type = 'directory';
93
+ }
94
+ }
95
+ /**
96
+ * Apply PAX attributes to header
97
+ */ export function applyPaxToHeader(header, pax) {
98
+ if (pax.path) header.name = pax.path;
99
+ if (pax.linkpath) header.linkname = pax.linkpath;
100
+ if (pax.size) header.size = parseInt(pax.size, 10);
101
+ if (pax.uid) header.uid = parseInt(pax.uid, 10);
102
+ if (pax.gid) header.gid = parseInt(pax.gid, 10);
103
+ if (pax.uname) header.uname = pax.uname;
104
+ if (pax.gname) header.gname = pax.gname;
105
+ if (pax.mtime) header.mtime = new Date(parseFloat(pax.mtime) * 1000);
106
+ }
107
+ /**
108
+ * Concatenate buffers (Node 0.8 compatible)
109
+ */ export function concatBuffers(buffers) {
110
+ if (buffers.length === 0) return Buffer.alloc ? Buffer.alloc(0) : new Buffer(0);
111
+ if (buffers.length === 1) return buffers[0];
112
+ const totalLength = buffers.reduce((sum, buf)=>sum + buf.length, 0);
113
+ if (Buffer.concat) {
114
+ return Buffer.concat(buffers, totalLength);
115
+ }
116
+ // Node 0.8 fallback
117
+ const result = allocBufferUnsafe(totalLength);
118
+ let offset = 0;
119
+ for(let i = 0; i < buffers.length; i++){
120
+ buffers[i].copy(result, offset);
121
+ offset += buffers[i].length;
122
+ }
123
+ return result;
124
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/tar/Extensions.ts"],"sourcesContent":["/**\n * Extensions - GNU/PAX extension handling for TAR\n *\n * Manages state and decoding for:\n * - GNU LongPath (type 'L') - paths > 100 chars\n * - GNU LongLink (type 'K') - symlink targets > 100 chars\n * - PAX Headers (type 'x') - extended attributes per-entry\n * - PAX Global Headers (type 'g') - extended attributes for all entries\n */\n\nimport { allocBufferUnsafe } from 'extract-base-iterator';\nimport { decodeLongPath, decodePax, type TarHeader } from './headers.ts';\n\n/**\n * Extension state for accumulating extension data across chunks\n */\nexport interface ExtensionState {\n /** GNU long path for next entry */\n gnuLongPath: string | null;\n /** GNU long link (symlink target) for next entry */\n gnuLongLink: string | null;\n /** PAX header for next entry */\n paxHeader: Record<string, string> | null;\n /** PAX global headers (apply to all subsequent entries) */\n paxGlobal: Record<string, string>;\n /** Accumulated extension data chunks */\n extensionData: Buffer[];\n /** Bytes remaining to read for current extension */\n extensionRemaining: number;\n}\n\n/**\n * Create a fresh extension state\n */\nexport function createExtensionState(): ExtensionState {\n return {\n gnuLongPath: null,\n gnuLongLink: null,\n paxHeader: null,\n paxGlobal: {},\n extensionData: [],\n extensionRemaining: 0,\n };\n}\n\n/**\n * Finalize extension data and update state\n *\n * @param state Extension state to update\n * @param currentState Parser state (STATE_GNU_LONG_PATH, etc.)\n * @param header Current header (for PAX global detection)\n * @param encoding Filename encoding\n */\nexport function finalizeExtension(state: ExtensionState, currentState: number, header: { type: string } | null, encoding: BufferEncoding): void {\n // Import state constants\n const STATE_GNU_LONG_PATH = 4;\n const STATE_GNU_LONG_LINK = 5;\n const STATE_PAX_HEADER = 6;\n\n // Concatenate all collected data\n const combined = concatBuffers(state.extensionData);\n state.extensionData = [];\n\n switch (currentState) {\n case STATE_GNU_LONG_PATH:\n state.gnuLongPath = decodeLongPath(combined, encoding);\n break;\n case STATE_GNU_LONG_LINK:\n state.gnuLongLink = decodeLongPath(combined, encoding);\n break;\n case STATE_PAX_HEADER:\n // Check if this was a global header\n if (header && header.type === 'pax-global-header') {\n const global = decodePax(combined);\n // Merge into global (don't replace, merge)\n for (const key in global) {\n // biome-ignore lint/suspicious/noPrototypeBuiltins: ES2021 compatibility\n if (global.hasOwnProperty(key)) {\n state.paxGlobal[key] = global[key];\n }\n }\n } else {\n state.paxHeader = decodePax(combined);\n }\n break;\n }\n}\n\n/**\n * Apply pending GNU/PAX extensions to a header\n *\n * @param header Header to modify\n * @param state Extension state (will be partially cleared)\n */\nexport function applyExtensions(header: TarHeader, state: ExtensionState): void {\n // Apply PAX global header first\n if (state.paxGlobal) {\n applyPaxToHeader(header, state.paxGlobal);\n }\n\n // Apply PAX header (per-entry, overrides global)\n if (state.paxHeader) {\n applyPaxToHeader(header, state.paxHeader);\n header.pax = state.paxHeader;\n state.paxHeader = null;\n }\n\n // Apply GNU long path (overrides PAX path)\n if (state.gnuLongPath !== null) {\n header.name = state.gnuLongPath;\n state.gnuLongPath = null;\n }\n\n // Apply GNU long link (overrides PAX linkpath)\n if (state.gnuLongLink !== null) {\n header.linkname = state.gnuLongLink;\n state.gnuLongLink = null;\n }\n\n // Handle old tar versions that use trailing / to indicate directories\n // This check is done AFTER extensions are applied so we use the final\n // resolved name (GNU long path or PAX path), not the truncated name field.\n if (header.type === 'file' && header.name && header.name[header.name.length - 1] === '/') {\n header.type = 'directory';\n }\n}\n\n/**\n * Apply PAX attributes to header\n */\nexport function applyPaxToHeader(header: TarHeader, pax: Record<string, string>): void {\n if (pax.path) header.name = pax.path;\n if (pax.linkpath) header.linkname = pax.linkpath;\n if (pax.size) header.size = parseInt(pax.size, 10);\n if (pax.uid) header.uid = parseInt(pax.uid, 10);\n if (pax.gid) header.gid = parseInt(pax.gid, 10);\n if (pax.uname) header.uname = pax.uname;\n if (pax.gname) header.gname = pax.gname;\n if (pax.mtime) header.mtime = new Date(parseFloat(pax.mtime) * 1000);\n}\n\n/**\n * Concatenate buffers (Node 0.8 compatible)\n */\nexport function concatBuffers(buffers: Buffer[]): Buffer {\n if (buffers.length === 0) return Buffer.alloc ? Buffer.alloc(0) : new Buffer(0);\n if (buffers.length === 1) return buffers[0];\n\n const totalLength = buffers.reduce((sum, buf) => sum + buf.length, 0);\n\n if (Buffer.concat) {\n return Buffer.concat(buffers, totalLength);\n }\n\n // Node 0.8 fallback\n const result = allocBufferUnsafe(totalLength);\n let offset = 0;\n for (let i = 0; i < buffers.length; i++) {\n buffers[i].copy(result, offset);\n offset += buffers[i].length;\n }\n return result;\n}\n"],"names":["allocBufferUnsafe","decodeLongPath","decodePax","createExtensionState","gnuLongPath","gnuLongLink","paxHeader","paxGlobal","extensionData","extensionRemaining","finalizeExtension","state","currentState","header","encoding","STATE_GNU_LONG_PATH","STATE_GNU_LONG_LINK","STATE_PAX_HEADER","combined","concatBuffers","type","global","key","hasOwnProperty","applyExtensions","applyPaxToHeader","pax","name","linkname","length","path","linkpath","size","parseInt","uid","gid","uname","gname","mtime","Date","parseFloat","buffers","Buffer","alloc","totalLength","reduce","sum","buf","concat","result","offset","i","copy"],"mappings":"AAAA;;;;;;;;CAQC,GAED,SAASA,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,cAAc,EAAEC,SAAS,QAAwB,eAAe;AAoBzE;;CAEC,GACD,OAAO,SAASC;IACd,OAAO;QACLC,aAAa;QACbC,aAAa;QACbC,WAAW;QACXC,WAAW,CAAC;QACZC,eAAe,EAAE;QACjBC,oBAAoB;IACtB;AACF;AAEA;;;;;;;CAOC,GACD,OAAO,SAASC,kBAAkBC,KAAqB,EAAEC,YAAoB,EAAEC,MAA+B,EAAEC,QAAwB;IACtI,yBAAyB;IACzB,MAAMC,sBAAsB;IAC5B,MAAMC,sBAAsB;IAC5B,MAAMC,mBAAmB;IAEzB,iCAAiC;IACjC,MAAMC,WAAWC,cAAcR,MAAMH,aAAa;IAClDG,MAAMH,aAAa,GAAG,EAAE;IAExB,OAAQI;QACN,KAAKG;YACHJ,MAAMP,WAAW,GAAGH,eAAeiB,UAAUJ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I,CAACH,QAAQC;QACxBA,UAAUT,OAAO,CAACU,EAAE,CAACtB,MAAM;IAC7B;IACA,OAAOoB;AACT"}
@@ -4,8 +4,36 @@
4
4
  * Event-based TAR parser that emits 'entry' events for each file.
5
5
  * Node 0.8 compatible.
6
6
  *
7
- * State Machine (Phase 1 MVP):
8
- * HEADER -> FILE_DATA -> PADDING -> HEADER
7
+ * State Machine:
8
+ * ```
9
+ * ┌─────────────────────────────────────────────┐
10
+ * │ │
11
+ * HEADER ─┬─ [file] ────> FILE_DATA ──> PADDING ─────────────────────>──┤
12
+ * │ │
13
+ * ├─ [gnu-long-path] ──> GNU_LONG_PATH ──> PADDING ──>──────────┤
14
+ * │ │
15
+ * ├─ [gnu-long-link] ──> GNU_LONG_LINK ──> PADDING ──>──────────┤
16
+ * │ │
17
+ * ├─ [pax-header] ──> PAX_HEADER ──> PADDING ──>────────────────┤
18
+ * │ │
19
+ * ├─ [gnu-sparse] ─┬─> SPARSE_EXTENDED ──> SPARSE_DATA ──>──────┤
20
+ * │ │ │
21
+ * │ └─> SPARSE_DATA ──> PADDING ──>──────────────┤
22
+ * │ │
23
+ * └─ [null header] ──> END │
24
+ * │
25
+ * <─────────────────────────────────────────────────────────────┘
26
+ * ```
27
+ *
28
+ * Extension handling:
29
+ * - GNU LongPath/LongLink headers store path for NEXT entry
30
+ * - PAX headers store attributes for NEXT entry (or all entries if global)
31
+ * - Extensions are applied when the actual file header is processed
32
+ *
33
+ * Events:
34
+ * 'entry' (header: TarHeader, stream: Readable, next: () => void)
35
+ * 'error' (err: Error)
36
+ * 'finish' ()
9
37
  */
10
38
  import { EventEmitter } from 'events';
11
39
  import { type ParseOptions } from './headers.js';
@@ -38,12 +66,7 @@ export default class TarExtract extends EventEmitter {
38
66
  private finished;
39
67
  private finishEmitted;
40
68
  private pendingEntry;
41
- private gnuLongPath;
42
- private gnuLongLink;
43
- private paxHeader;
44
- private paxGlobal;
45
- private extensionData;
46
- private extensionRemaining;
69
+ private extState;
47
70
  private sparseInfo;
48
71
  private sparseStream;
49
72
  private sparseDataRemaining;
@@ -78,26 +101,10 @@ export default class TarExtract extends EventEmitter {
78
101
  * Process header state
79
102
  */
80
103
  private _processHeader;
81
- /**
82
- * Apply pending GNU/PAX extensions to a header
83
- */
84
- private _applyExtensions;
85
- /**
86
- * Apply PAX attributes to header
87
- */
88
- private _applyPaxToHeader;
89
104
  /**
90
105
  * Process extension data (GNU long path/link, PAX headers)
91
106
  */
92
107
  private _processExtensionData;
93
- /**
94
- * Finalize extension data collection
95
- */
96
- private _finalizeExtension;
97
- /**
98
- * Concatenate buffers (Node 0.8 compatible fallback)
99
- */
100
- private _concatBuffers;
101
108
  /**
102
109
  * Process file data state
103
110
  */