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/FileEntry.d.cts
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/cjs/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/cjs/FileEntry.js
CHANGED
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return TarFileEntry;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
|
|
11
12
|
var _extractbaseiterator = require("extract-base-iterator");
|
|
12
13
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
13
14
|
var _onone = /*#__PURE__*/ _interop_require_default(require("on-one"));
|
|
@@ -118,19 +119,29 @@ var TarFileEntry = /*#__PURE__*/ function(FileEntry) {
|
|
|
118
119
|
return;
|
|
119
120
|
}
|
|
120
121
|
var stream = this.stream;
|
|
121
|
-
this.stream = null;
|
|
122
|
+
this.stream = null; // Prevent reuse
|
|
123
|
+
// Use once since errors can come from either stream
|
|
124
|
+
var cb = (0, _calloncefn.default)(function(err) {
|
|
125
|
+
err ? callback(err) : (0, _extractbaseiterator.waitForAccess)(fullPath, callback); // gunzip stream returns prematurely occasionally
|
|
126
|
+
});
|
|
122
127
|
try {
|
|
123
|
-
var
|
|
124
|
-
(
|
|
128
|
+
var writeStream = _fs.default.createWriteStream(fullPath);
|
|
129
|
+
// 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
|
|
132
|
+
var ws = writeStream;
|
|
133
|
+
if (typeof ws.destroy === 'function') ws.destroy();
|
|
134
|
+
cb(err);
|
|
135
|
+
});
|
|
136
|
+
// Pipe and listen for write stream completion/errors
|
|
137
|
+
stream.pipe(writeStream);
|
|
138
|
+
(0, _onone.default)(writeStream, [
|
|
125
139
|
'error',
|
|
126
|
-
'end',
|
|
127
140
|
'close',
|
|
128
141
|
'finish'
|
|
129
|
-
],
|
|
130
|
-
err ? callback(err) : (0, _extractbaseiterator.waitForAccess)(fullPath, callback); // gunzip stream returns prematurely occasionally
|
|
131
|
-
});
|
|
142
|
+
], cb);
|
|
132
143
|
} catch (err) {
|
|
133
|
-
|
|
144
|
+
cb(err);
|
|
134
145
|
}
|
|
135
146
|
};
|
|
136
147
|
_proto.destroy = function 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":["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;a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C,SAAS,SAAChB;gBAClB,2CAA2C;gBAC3C,IAAMiB,KAAKJ;gBACX,IAAI,OAAOI,GAAGC,OAAO,KAAK,YAAYD,GAAGC,OAAO;gBAChDR,GAAGV;YACL;YAEA,qDAAqD;YACrDV,OAAO6B,IAAI,CAACN;YACZO,IAAAA,cAAE,EAACP,aAAa;gBAAC;gBAAS;gBAAS;aAAS,EAAEH;QAChD,EAAE,OAAOV,KAAK;YACZU,GAAGV;QACL;IACF;IAEAkB,OAAAA,OAUC,GAVDA,SAAAA;QACErB,8BAAS,CAACC,SAAS,CAACoB,OAAO,CAACnB,IAAI,CAAC,IAAI;QACrC,IAAI,IAAI,CAACT,MAAM,EAAE;YACf,IAAI,CAACA,MAAM,CAAC+B,MAAM,IAAI,eAAe;YACrC,IAAI,CAAC/B,MAAM,GAAG;QAChB;QACA,IAAI,IAAI,CAACC,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACU,OAAO;YACjB,IAAI,CAACV,IAAI,GAAG;QACd;IACF;WA9EmBH;EAAqBS,8BAAS"}
|
|
@@ -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,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/cjs/TarIterator.js
CHANGED
|
@@ -9,9 +9,8 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
|
|
12
|
-
var _extractbaseiterator = /*#__PURE__*/
|
|
12
|
+
var _extractbaseiterator = /*#__PURE__*/ _interop_require_wildcard(require("extract-base-iterator"));
|
|
13
13
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
14
|
-
var _Lockts = /*#__PURE__*/ _interop_require_default(require("./lib/Lock.js"));
|
|
15
14
|
var _nextEntryts = /*#__PURE__*/ _interop_require_default(require("./nextEntry.js"));
|
|
16
15
|
var _TarExtractts = /*#__PURE__*/ _interop_require_default(require("./tar/TarExtract.js"));
|
|
17
16
|
function _assert_this_initialized(self) {
|
|
@@ -53,6 +52,47 @@ function _interop_require_default(obj) {
|
|
|
53
52
|
default: obj
|
|
54
53
|
};
|
|
55
54
|
}
|
|
55
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
56
|
+
if (typeof WeakMap !== "function") return null;
|
|
57
|
+
var cacheBabelInterop = new WeakMap();
|
|
58
|
+
var cacheNodeInterop = new WeakMap();
|
|
59
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
60
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
61
|
+
})(nodeInterop);
|
|
62
|
+
}
|
|
63
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
64
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
65
|
+
return obj;
|
|
66
|
+
}
|
|
67
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
68
|
+
return {
|
|
69
|
+
default: obj
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
73
|
+
if (cache && cache.has(obj)) {
|
|
74
|
+
return cache.get(obj);
|
|
75
|
+
}
|
|
76
|
+
var newObj = {
|
|
77
|
+
__proto__: null
|
|
78
|
+
};
|
|
79
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
80
|
+
for(var key in obj){
|
|
81
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
82
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
83
|
+
if (desc && (desc.get || desc.set)) {
|
|
84
|
+
Object.defineProperty(newObj, key, desc);
|
|
85
|
+
} else {
|
|
86
|
+
newObj[key] = obj[key];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
newObj.default = obj;
|
|
91
|
+
if (cache) {
|
|
92
|
+
cache.set(obj, newObj);
|
|
93
|
+
}
|
|
94
|
+
return newObj;
|
|
95
|
+
}
|
|
56
96
|
function _possible_constructor_return(self, call) {
|
|
57
97
|
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
58
98
|
return call;
|
|
@@ -88,8 +128,10 @@ var TarIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
88
128
|
_this = _call_super(this, TarIterator, [
|
|
89
129
|
options
|
|
90
130
|
]);
|
|
91
|
-
_this.lock = new
|
|
92
|
-
_this.lock.
|
|
131
|
+
_this.lock = new _extractbaseiterator.Lock();
|
|
132
|
+
_this.lock.onDestroy = function(err) {
|
|
133
|
+
return _extractbaseiterator.default.prototype.end.call(_this, err);
|
|
134
|
+
};
|
|
93
135
|
var cancelled = false;
|
|
94
136
|
var setup = function() {
|
|
95
137
|
cancelled = true;
|
|
@@ -99,28 +141,33 @@ var TarIterator = /*#__PURE__*/ function(BaseIterator) {
|
|
|
99
141
|
// Note: options passed here are ExtractOptions (strip, force, etc.)
|
|
100
142
|
// TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different
|
|
101
143
|
_this.extract = new _TarExtractts.default();
|
|
102
|
-
_this.lock.extract = _this.extract;
|
|
103
144
|
var pipe = function(cb) {
|
|
104
145
|
try {
|
|
105
146
|
if (typeof source === 'string') source = _fs.default.createReadStream(source);
|
|
106
147
|
} catch (err) {
|
|
107
148
|
cb(err);
|
|
108
149
|
}
|
|
109
|
-
//
|
|
110
|
-
|
|
150
|
+
// Register cleanup for source stream
|
|
151
|
+
var stream = source;
|
|
152
|
+
_this.lock.registerCleanup(function() {
|
|
153
|
+
var s = stream;
|
|
154
|
+
if (typeof s.destroy === 'function') s.destroy();
|
|
155
|
+
});
|
|
111
156
|
var end = (0, _calloncefn.default)(cb);
|
|
112
157
|
var self = _this;
|
|
158
|
+
var firstData = true;
|
|
113
159
|
source.on('data', function onData(chunk) {
|
|
114
160
|
try {
|
|
115
161
|
if (self.extract) self.extract.write(chunk);
|
|
162
|
+
if (firstData) {
|
|
163
|
+
firstData = false;
|
|
164
|
+
end();
|
|
165
|
+
}
|
|
116
166
|
} catch (err) {
|
|
117
167
|
// Handle synchronous errors from TarExtract (e.g., invalid format)
|
|
118
168
|
end(err);
|
|
119
169
|
}
|
|
120
170
|
});
|
|
121
|
-
source.on('data', function onFirstData() {
|
|
122
|
-
end();
|
|
123
|
-
});
|
|
124
171
|
source.on('error', end);
|
|
125
172
|
source.on('end', function onEnd() {
|
|
126
173
|
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":["TarIterator","source","options","lock","Lock","onDestroy","err","BaseIterator","prototype","end","call","cancelled","setup","processing","push","extract","TarExtract","pipe","cb","fs","createReadStream","stream","registerCleanup","s","destroy","once","self","firstData","on","onData","chunk","write","onEnd","remove","done","nextEntry","bind","release"],"mappings":";;;;;;;eASqBA;;;iEATJ;2EACkB;yDACpB;kEAEO;mEACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIR,IAAA,AAAMA,4BAAN;;cAAMA;aAAAA,YAMPC,MAAsC;YAAEC,UAAAA,iEAA0B,CAAC;gCAN5DF;;gBAOjB,kBAPiBA;YAOXE;;QACN,MAAKC,IAAI,GAAG,IAAIC,yBAAI;QACpB,MAAKD,IAAI,CAACE,SAAS,GAAG,SAACC;mBAAQC,4BAAY,CAACC,SAAS,CAACC,GAAG,CAACC,IAAI,QAAOJ;;QAErE,IAAIK,YAAY;QAChB,IAAMC,QAAQ;YACZD,YAAY;QACd;QACA,MAAKE,UAAU,CAACC,IAAI,CAACF;QAErB,uDAAuD;QACvD,oEAAoE;QACpE,gFAAgF;QAChF,MAAKG,OAAO,GAAG,IAAIC,qBAAU;QAE7B,IAAMC,OAAO,SAACC;YACZ,IAAI;gBACF,IAAI,OAAOjB,WAAW,UA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ist/cjs/nextEntry.d.cts
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/cjs/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/cjs/nextEntry.js
CHANGED
|
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _calloncefn = /*#__PURE__*/ _interop_require_default(require("call-once-fn"));
|
|
12
12
|
var _extractbaseiterator = require("extract-base-iterator");
|
|
13
|
-
var _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
14
13
|
var _FileEntryts = /*#__PURE__*/ _interop_require_default(require("./FileEntry.js"));
|
|
15
14
|
function _define_property(obj, key, value) {
|
|
16
15
|
if (key in obj) {
|
|
@@ -45,10 +44,6 @@ function _object_spread(target) {
|
|
|
45
44
|
}
|
|
46
45
|
return target;
|
|
47
46
|
}
|
|
48
|
-
// Node 0.8 compatible setImmediate (setImmediate was added in Node 0.10)
|
|
49
|
-
var _setImmediate = typeof setImmediate === 'function' ? setImmediate : typeof process !== 'undefined' && typeof process.nextTick === 'function' ? process.nextTick : function setImmediateFallback(fn) {
|
|
50
|
-
setTimeout(fn, 0);
|
|
51
|
-
};
|
|
52
47
|
function nextEntry(next, iterator, callback) {
|
|
53
48
|
// Guard: bail early if iterator already ended
|
|
54
49
|
if (!iterator.lock || iterator.isDone()) {
|
|
@@ -65,9 +60,8 @@ function nextEntry(next, iterator, callback) {
|
|
|
65
60
|
extract.removeListener('finish', onEnd);
|
|
66
61
|
// keep processing
|
|
67
62
|
if (entry) iterator.push(nextEntry.bind(null, next));
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
_setImmediate(function() {
|
|
63
|
+
// Defer the callback invocation to ensure proper async behavior with the BaseIterator
|
|
64
|
+
setTimeout(function() {
|
|
71
65
|
err ? callback(err) : callback(null, entry ? {
|
|
72
66
|
done: false,
|
|
73
67
|
value: entry
|
|
@@ -75,7 +69,7 @@ function nextEntry(next, iterator, callback) {
|
|
|
75
69
|
done: true,
|
|
76
70
|
value: null
|
|
77
71
|
});
|
|
78
|
-
});
|
|
72
|
+
}, 0);
|
|
79
73
|
});
|
|
80
74
|
// Use nextCallback for all events to ensure once() wrapper is respected
|
|
81
75
|
var onError = function(err) {
|
|
@@ -91,7 +85,7 @@ function nextEntry(next, iterator, callback) {
|
|
|
91
85
|
return nextCallback(null, null, next);
|
|
92
86
|
}
|
|
93
87
|
var attributes = _object_spread({}, header);
|
|
94
|
-
attributes.path =
|
|
88
|
+
attributes.path = (0, _extractbaseiterator.normalizePath)(header.name);
|
|
95
89
|
attributes.mtime = new Date(attributes.mtime);
|
|
96
90
|
switch(attributes.type){
|
|
97
91
|
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":["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;;;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,sFAAsF;QACtFmB,WAAW;YAC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EAO,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"}
|
|
@@ -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,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,136 @@
|
|
|
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
|
+
*/ "use strict";
|
|
10
|
+
Object.defineProperty(exports, "__esModule", {
|
|
11
|
+
value: true
|
|
12
|
+
});
|
|
13
|
+
function _export(target, all) {
|
|
14
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
_export(exports, {
|
|
20
|
+
get applyExtensions () {
|
|
21
|
+
return applyExtensions;
|
|
22
|
+
},
|
|
23
|
+
get applyPaxToHeader () {
|
|
24
|
+
return applyPaxToHeader;
|
|
25
|
+
},
|
|
26
|
+
get concatBuffers () {
|
|
27
|
+
return concatBuffers;
|
|
28
|
+
},
|
|
29
|
+
get createExtensionState () {
|
|
30
|
+
return createExtensionState;
|
|
31
|
+
},
|
|
32
|
+
get finalizeExtension () {
|
|
33
|
+
return finalizeExtension;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var _extractbaseiterator = require("extract-base-iterator");
|
|
37
|
+
var _headersts = require("./headers.js");
|
|
38
|
+
function createExtensionState() {
|
|
39
|
+
return {
|
|
40
|
+
gnuLongPath: null,
|
|
41
|
+
gnuLongLink: null,
|
|
42
|
+
paxHeader: null,
|
|
43
|
+
paxGlobal: {},
|
|
44
|
+
extensionData: [],
|
|
45
|
+
extensionRemaining: 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function finalizeExtension(state, currentState, header, encoding) {
|
|
49
|
+
// Import state constants
|
|
50
|
+
var STATE_GNU_LONG_PATH = 4;
|
|
51
|
+
var STATE_GNU_LONG_LINK = 5;
|
|
52
|
+
var STATE_PAX_HEADER = 6;
|
|
53
|
+
// Concatenate all collected data
|
|
54
|
+
var combined = concatBuffers(state.extensionData);
|
|
55
|
+
state.extensionData = [];
|
|
56
|
+
switch(currentState){
|
|
57
|
+
case STATE_GNU_LONG_PATH:
|
|
58
|
+
state.gnuLongPath = (0, _headersts.decodeLongPath)(combined, encoding);
|
|
59
|
+
break;
|
|
60
|
+
case STATE_GNU_LONG_LINK:
|
|
61
|
+
state.gnuLongLink = (0, _headersts.decodeLongPath)(combined, encoding);
|
|
62
|
+
break;
|
|
63
|
+
case STATE_PAX_HEADER:
|
|
64
|
+
// Check if this was a global header
|
|
65
|
+
if (header && header.type === 'pax-global-header') {
|
|
66
|
+
var global = (0, _headersts.decodePax)(combined);
|
|
67
|
+
// Merge into global (don't replace, merge)
|
|
68
|
+
for(var key in global){
|
|
69
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: ES2021 compatibility
|
|
70
|
+
if (global.hasOwnProperty(key)) {
|
|
71
|
+
state.paxGlobal[key] = global[key];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
state.paxHeader = (0, _headersts.decodePax)(combined);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function applyExtensions(header, state) {
|
|
81
|
+
// Apply PAX global header first
|
|
82
|
+
if (state.paxGlobal) {
|
|
83
|
+
applyPaxToHeader(header, state.paxGlobal);
|
|
84
|
+
}
|
|
85
|
+
// Apply PAX header (per-entry, overrides global)
|
|
86
|
+
if (state.paxHeader) {
|
|
87
|
+
applyPaxToHeader(header, state.paxHeader);
|
|
88
|
+
header.pax = state.paxHeader;
|
|
89
|
+
state.paxHeader = null;
|
|
90
|
+
}
|
|
91
|
+
// Apply GNU long path (overrides PAX path)
|
|
92
|
+
if (state.gnuLongPath !== null) {
|
|
93
|
+
header.name = state.gnuLongPath;
|
|
94
|
+
state.gnuLongPath = null;
|
|
95
|
+
}
|
|
96
|
+
// Apply GNU long link (overrides PAX linkpath)
|
|
97
|
+
if (state.gnuLongLink !== null) {
|
|
98
|
+
header.linkname = state.gnuLongLink;
|
|
99
|
+
state.gnuLongLink = null;
|
|
100
|
+
}
|
|
101
|
+
// Handle old tar versions that use trailing / to indicate directories
|
|
102
|
+
// This check is done AFTER extensions are applied so we use the final
|
|
103
|
+
// resolved name (GNU long path or PAX path), not the truncated name field.
|
|
104
|
+
if (header.type === 'file' && header.name && header.name[header.name.length - 1] === '/') {
|
|
105
|
+
header.type = 'directory';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function applyPaxToHeader(header, pax) {
|
|
109
|
+
if (pax.path) header.name = pax.path;
|
|
110
|
+
if (pax.linkpath) header.linkname = pax.linkpath;
|
|
111
|
+
if (pax.size) header.size = parseInt(pax.size, 10);
|
|
112
|
+
if (pax.uid) header.uid = parseInt(pax.uid, 10);
|
|
113
|
+
if (pax.gid) header.gid = parseInt(pax.gid, 10);
|
|
114
|
+
if (pax.uname) header.uname = pax.uname;
|
|
115
|
+
if (pax.gname) header.gname = pax.gname;
|
|
116
|
+
if (pax.mtime) header.mtime = new Date(parseFloat(pax.mtime) * 1000);
|
|
117
|
+
}
|
|
118
|
+
function concatBuffers(buffers) {
|
|
119
|
+
if (buffers.length === 0) return Buffer.alloc ? Buffer.alloc(0) : new Buffer(0);
|
|
120
|
+
if (buffers.length === 1) return buffers[0];
|
|
121
|
+
var totalLength = buffers.reduce(function(sum, buf) {
|
|
122
|
+
return sum + buf.length;
|
|
123
|
+
}, 0);
|
|
124
|
+
if (Buffer.concat) {
|
|
125
|
+
return Buffer.concat(buffers, totalLength);
|
|
126
|
+
}
|
|
127
|
+
// Node 0.8 fallback
|
|
128
|
+
var result = (0, _extractbaseiterator.allocBufferUnsafe)(totalLength);
|
|
129
|
+
var offset = 0;
|
|
130
|
+
for(var i = 0; i < buffers.length; i++){
|
|
131
|
+
buffers[i].copy(result, offset);
|
|
132
|
+
offset += buffers[i].length;
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|