tar-iterator 3.1.11 → 3.3.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.
- package/dist/cjs/FileEntry.d.cts +5 -4
- package/dist/cjs/FileEntry.d.ts +5 -4
- package/dist/cjs/FileEntry.js +19 -8
- package/dist/cjs/FileEntry.js.map +1 -1
- package/dist/cjs/TarIterator.d.cts +5 -6
- package/dist/cjs/TarIterator.d.ts +5 -6
- package/dist/cjs/TarIterator.js +57 -10
- package/dist/cjs/TarIterator.js.map +1 -1
- package/dist/cjs/nextEntry.d.cts +3 -3
- package/dist/cjs/nextEntry.d.ts +3 -3
- package/dist/cjs/nextEntry.js +4 -10
- package/dist/cjs/nextEntry.js.map +1 -1
- package/dist/cjs/tar/Extensions.d.cts +57 -0
- package/dist/cjs/tar/Extensions.d.ts +57 -0
- package/dist/cjs/tar/Extensions.js +136 -0
- package/dist/cjs/tar/Extensions.js.map +1 -0
- package/dist/cjs/tar/TarExtract.d.cts +31 -24
- package/dist/cjs/tar/TarExtract.d.ts +31 -24
- package/dist/cjs/tar/TarExtract.js +52 -111
- package/dist/cjs/tar/TarExtract.js.map +1 -1
- package/dist/cjs/types.d.cts +5 -4
- package/dist/cjs/types.d.ts +5 -4
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/FileEntry.d.ts +5 -4
- package/dist/esm/FileEntry.js +19 -8
- package/dist/esm/FileEntry.js.map +1 -1
- package/dist/esm/TarIterator.d.ts +5 -6
- package/dist/esm/TarIterator.js +13 -9
- package/dist/esm/TarIterator.js.map +1 -1
- package/dist/esm/nextEntry.d.ts +3 -3
- package/dist/esm/nextEntry.js +5 -11
- package/dist/esm/nextEntry.js.map +1 -1
- package/dist/esm/tar/Extensions.d.ts +57 -0
- package/dist/esm/tar/Extensions.js +124 -0
- package/dist/esm/tar/Extensions.js.map +1 -0
- package/dist/esm/tar/TarExtract.d.ts +31 -24
- package/dist/esm/tar/TarExtract.js +54 -111
- package/dist/esm/tar/TarExtract.js.map +1 -1
- package/dist/esm/types.d.ts +5 -4
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.js.map +1 -1
- package/package.json +18 -19
- package/dist/cjs/lib/Lock.d.cts +0 -13
- package/dist/cjs/lib/Lock.d.ts +0 -13
- package/dist/cjs/lib/Lock.js +0 -62
- package/dist/cjs/lib/Lock.js.map +0 -1
- package/dist/esm/lib/Lock.d.ts +0 -13
- package/dist/esm/lib/Lock.js +0 -38
- package/dist/esm/lib/Lock.js.map +0 -1
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/types.ts"],"sourcesContent":["export { DirectoryEntry, type
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/types.ts"],"sourcesContent":["export { DirectoryEntry, type ExtractOptions, LinkEntry, Lock, SymbolicLinkEntry } from 'extract-base-iterator';\nexport { default as FileEntry } from './FileEntry.ts';\n\nimport type { DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';\nimport type FileEntry from './FileEntry.ts';\n\n// Tar-specific Entry union type with tar-specific FileEntry\nexport type Entry = DirectoryEntry | FileEntry | LinkEntry | SymbolicLinkEntry;\n\nexport type EntryCallback = (error?: Error, result?: IteratorResult<Entry>) => void;\n"],"names":["DirectoryEntry","FileEntry","LinkEntry","Lock","SymbolicLinkEntry"],"mappings":";;;;;;;;;;;QAASA;eAAAA,mCAAc;;QACHC;eAAAA,oBAAS;;QADiBC;eAAAA,8BAAS;;QAAEC;eAAAA,yBAAI;;QAAEC;eAAAA,sCAAiB;;;mCAAQ;kEACnD"}
|
package/dist/esm/FileEntry.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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;
|
|
6
5
|
private stream;
|
|
7
6
|
constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock);
|
|
8
|
-
create(dest: string,
|
|
9
|
-
|
|
7
|
+
create(dest: string, callback: NoParamCallback): void;
|
|
8
|
+
create(dest: string, options: ExtractOptions, callback: NoParamCallback): void;
|
|
9
|
+
create(dest: string, options?: ExtractOptions): Promise<boolean>;
|
|
10
|
+
_writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): void;
|
|
10
11
|
destroy(): void;
|
|
11
12
|
}
|
package/dist/esm/FileEntry.js
CHANGED
|
@@ -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,29 @@ 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
|
|
33
|
-
|
|
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
|
-
'end',
|
|
36
49
|
'close',
|
|
37
50
|
'finish'
|
|
38
|
-
],
|
|
39
|
-
err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally
|
|
40
|
-
});
|
|
51
|
+
], cb);
|
|
41
52
|
} catch (err) {
|
|
42
|
-
|
|
53
|
+
cb(err);
|
|
43
54
|
}
|
|
44
55
|
}
|
|
45
56
|
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
|
|
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,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AAI,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,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
|
}
|
package/dist/esm/TarIterator.js
CHANGED
|
@@ -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.
|
|
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
|
-
//
|
|
38
|
-
|
|
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
|
|
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 = (): void => {\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,aAAac,SAAS,CAACR,GAAG,CAACS,IAAI,CAAC,IAAI,EAAER;QAErE,IAAIS,Y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nextEntry.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type Iterator from './TarIterator.js';
|
|
2
2
|
import type { Entry, EntryCallback } from './types.js';
|
|
3
|
-
export type TarNext = () =>
|
|
4
|
-
export type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) =>
|
|
5
|
-
export default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback):
|
|
3
|
+
export type TarNext = () => void;
|
|
4
|
+
export type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => void;
|
|
5
|
+
export default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): void;
|
package/dist/esm/nextEntry.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
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
|
-
};
|
|
9
4
|
export default function nextEntry(next, iterator, callback) {
|
|
10
5
|
// Guard: bail early if iterator already ended
|
|
11
6
|
if (!iterator.lock || iterator.isDone()) {
|
|
@@ -22,9 +17,8 @@ export default function nextEntry(next, iterator, callback) {
|
|
|
22
17
|
extract.removeListener('finish', onEnd);
|
|
23
18
|
// keep processing
|
|
24
19
|
if (entry) iterator.push(nextEntry.bind(null, next));
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
_setImmediate(()=>{
|
|
20
|
+
// Defer the callback invocation to ensure proper async behavior with the BaseIterator
|
|
21
|
+
setTimeout(()=>{
|
|
28
22
|
err ? callback(err) : callback(null, entry ? {
|
|
29
23
|
done: false,
|
|
30
24
|
value: entry
|
|
@@ -32,7 +26,7 @@ export default function nextEntry(next, iterator, callback) {
|
|
|
32
26
|
done: true,
|
|
33
27
|
value: null
|
|
34
28
|
});
|
|
35
|
-
});
|
|
29
|
+
}, 0);
|
|
36
30
|
});
|
|
37
31
|
// Use nextCallback for all events to ensure once() wrapper is respected
|
|
38
32
|
const onError = (err)=>nextCallback(err);
|
|
@@ -46,7 +40,7 @@ export default function nextEntry(next, iterator, callback) {
|
|
|
46
40
|
const attributes = {
|
|
47
41
|
...header
|
|
48
42
|
};
|
|
49
|
-
attributes.path = header.name
|
|
43
|
+
attributes.path = normalizePath(header.name);
|
|
50
44
|
attributes.mtime = new Date(attributes.mtime);
|
|
51
45
|
switch(attributes.type){
|
|
52
46
|
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
|
|
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"],"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K,GAAG,IAAIC,KAAKJ,WAAWG,KAAK;QAE5C,OAAQH,WAAWK,IAAI;YACrB,KAAK;gBACHP,OAAOC,MAAM,IAAI,eAAe;gBAChC,OAAOZ,aAAa,MAAM,IAAIf,eAAe4B,aAAatB;YAC5D,KAAK;gBACHoB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWM,QAAQ,GAAGT,OAAOU,QAAQ;gBACrC,OAAOpB,aAAa,MAAM,IAAIZ,kBAAkByB,aAAatB;YAC/D,KAAK;gBACHoB,OAAOC,MAAM,IAAI,eAAe;gBAChCC,WAAWM,QAAQ,GAAGT,OAAOU,QAAQ;gBACrC,OAAOpB,aAAa,MAAM,IAAId,UAAU2B,aAAatB;YACvD,KAAK;gBACH,OAAOS,aAAa,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"}
|
|
@@ -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,KA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AAEsB,IAAK;QACvCV,OAAO,CAACU,EAAE,CAACC,IAAI,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
|
|
8
|
-
*
|
|
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
|
|
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
|
*/
|