tar-iterator 2.2.9 → 3.0.1

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 (79) hide show
  1. package/dist/cjs/FileEntry.js +1 -1
  2. package/dist/cjs/FileEntry.js.map +1 -1
  3. package/dist/cjs/TarIterator.d.cts +4 -1
  4. package/dist/cjs/TarIterator.d.ts +4 -1
  5. package/dist/cjs/TarIterator.js +19 -46
  6. package/dist/cjs/TarIterator.js.map +1 -1
  7. package/dist/cjs/index.d.cts +1 -0
  8. package/dist/cjs/index.d.ts +1 -0
  9. package/dist/cjs/index.js +12 -3
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/cjs/nextEntry.js +27 -10
  12. package/dist/cjs/nextEntry.js.map +1 -1
  13. package/dist/cjs/tar/BufferList.d.cts +31 -0
  14. package/dist/cjs/tar/BufferList.d.ts +31 -0
  15. package/dist/cjs/tar/BufferList.js +104 -0
  16. package/dist/cjs/tar/BufferList.js.map +1 -0
  17. package/dist/cjs/tar/EntryStream.d.cts +4 -0
  18. package/dist/cjs/tar/EntryStream.d.ts +4 -0
  19. package/dist/cjs/tar/EntryStream.js +22 -0
  20. package/dist/cjs/tar/EntryStream.js.map +1 -0
  21. package/dist/cjs/tar/TarExtract.d.cts +125 -0
  22. package/dist/cjs/tar/TarExtract.d.ts +125 -0
  23. package/dist/cjs/tar/TarExtract.js +608 -0
  24. package/dist/cjs/tar/TarExtract.js.map +1 -0
  25. package/dist/cjs/tar/constants.d.cts +70 -0
  26. package/dist/cjs/tar/constants.d.ts +70 -0
  27. package/dist/cjs/tar/constants.js +288 -0
  28. package/dist/cjs/tar/constants.js.map +1 -0
  29. package/dist/cjs/tar/errors.d.cts +28 -0
  30. package/dist/cjs/tar/errors.d.ts +28 -0
  31. package/dist/cjs/tar/errors.js +34 -0
  32. package/dist/cjs/tar/errors.js.map +1 -0
  33. package/dist/cjs/tar/headers.d.cts +81 -0
  34. package/dist/cjs/tar/headers.d.ts +81 -0
  35. package/dist/cjs/tar/headers.js +285 -0
  36. package/dist/cjs/tar/headers.js.map +1 -0
  37. package/dist/cjs/tar/index.d.cts +9 -0
  38. package/dist/cjs/tar/index.d.ts +9 -0
  39. package/dist/cjs/tar/index.js +45 -0
  40. package/dist/cjs/tar/index.js.map +1 -0
  41. package/dist/cjs/tar/sparse.d.cts +91 -0
  42. package/dist/cjs/tar/sparse.d.ts +91 -0
  43. package/dist/cjs/tar/sparse.js +273 -0
  44. package/dist/cjs/tar/sparse.js.map +1 -0
  45. package/dist/esm/FileEntry.js +1 -1
  46. package/dist/esm/FileEntry.js.map +1 -1
  47. package/dist/esm/TarIterator.d.ts +4 -1
  48. package/dist/esm/TarIterator.js +20 -4
  49. package/dist/esm/TarIterator.js.map +1 -1
  50. package/dist/esm/index.d.ts +1 -0
  51. package/dist/esm/index.js +1 -0
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/nextEntry.js +27 -10
  54. package/dist/esm/nextEntry.js.map +1 -1
  55. package/dist/esm/tar/BufferList.d.ts +31 -0
  56. package/dist/esm/tar/BufferList.js +85 -0
  57. package/dist/esm/tar/BufferList.js.map +1 -0
  58. package/dist/esm/tar/EntryStream.d.ts +4 -0
  59. package/dist/esm/tar/EntryStream.js +3 -0
  60. package/dist/esm/tar/EntryStream.js.map +1 -0
  61. package/dist/esm/tar/TarExtract.d.ts +125 -0
  62. package/dist/esm/tar/TarExtract.js +538 -0
  63. package/dist/esm/tar/TarExtract.js.map +1 -0
  64. package/dist/esm/tar/constants.d.ts +70 -0
  65. package/dist/esm/tar/constants.js +100 -0
  66. package/dist/esm/tar/constants.js.map +1 -0
  67. package/dist/esm/tar/errors.d.ts +28 -0
  68. package/dist/esm/tar/errors.js +23 -0
  69. package/dist/esm/tar/errors.js.map +1 -0
  70. package/dist/esm/tar/headers.d.ts +81 -0
  71. package/dist/esm/tar/headers.js +271 -0
  72. package/dist/esm/tar/headers.js.map +1 -0
  73. package/dist/esm/tar/index.d.ts +9 -0
  74. package/dist/esm/tar/index.js +8 -0
  75. package/dist/esm/tar/index.js.map +1 -0
  76. package/dist/esm/tar/sparse.d.ts +91 -0
  77. package/dist/esm/tar/sparse.js +176 -0
  78. package/dist/esm/tar/sparse.js.map +1 -0
  79. package/package.json +7 -8
@@ -0,0 +1,608 @@
1
+ /**
2
+ * TarExtract - Streaming TAR extraction
3
+ *
4
+ * Event-based TAR parser that emits 'entry' events for each file.
5
+ * Node 0.8 compatible.
6
+ *
7
+ * State Machine (Phase 1 MVP):
8
+ * HEADER -> FILE_DATA -> PADDING -> HEADER
9
+ */ "use strict";
10
+ Object.defineProperty(exports, "__esModule", {
11
+ value: true
12
+ });
13
+ Object.defineProperty(exports, "default", {
14
+ enumerable: true,
15
+ get: function() {
16
+ return TarExtract;
17
+ }
18
+ });
19
+ var _events = require("events");
20
+ var _BufferListts = /*#__PURE__*/ _interop_require_default(require("./BufferList.js"));
21
+ var _constantsts = require("./constants.js");
22
+ var _EntryStreamts = /*#__PURE__*/ _interop_require_default(require("./EntryStream.js"));
23
+ var _headersts = require("./headers.js");
24
+ var _sparsets = require("./sparse.js");
25
+ function _assert_this_initialized(self) {
26
+ if (self === void 0) {
27
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
28
+ }
29
+ return self;
30
+ }
31
+ function _call_super(_this, derived, args) {
32
+ derived = _get_prototype_of(derived);
33
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
34
+ }
35
+ function _class_call_check(instance, Constructor) {
36
+ if (!(instance instanceof Constructor)) {
37
+ throw new TypeError("Cannot call a class as a function");
38
+ }
39
+ }
40
+ function _get_prototype_of(o) {
41
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
42
+ return o.__proto__ || Object.getPrototypeOf(o);
43
+ };
44
+ return _get_prototype_of(o);
45
+ }
46
+ function _inherits(subClass, superClass) {
47
+ if (typeof superClass !== "function" && superClass !== null) {
48
+ throw new TypeError("Super expression must either be null or a function");
49
+ }
50
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
51
+ constructor: {
52
+ value: subClass,
53
+ writable: true,
54
+ configurable: true
55
+ }
56
+ });
57
+ if (superClass) _set_prototype_of(subClass, superClass);
58
+ }
59
+ function _interop_require_default(obj) {
60
+ return obj && obj.__esModule ? obj : {
61
+ default: obj
62
+ };
63
+ }
64
+ function _possible_constructor_return(self, call) {
65
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
66
+ return call;
67
+ }
68
+ return _assert_this_initialized(self);
69
+ }
70
+ function _set_prototype_of(o, p) {
71
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
72
+ o.__proto__ = p;
73
+ return o;
74
+ };
75
+ return _set_prototype_of(o, p);
76
+ }
77
+ function _type_of(obj) {
78
+ "@swc/helpers - typeof";
79
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
80
+ }
81
+ function _is_native_reflect_construct() {
82
+ try {
83
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
84
+ } catch (_) {}
85
+ return (_is_native_reflect_construct = function() {
86
+ return !!result;
87
+ })();
88
+ }
89
+ // Parser states
90
+ var STATE_HEADER = 0;
91
+ var STATE_FILE_DATA = 1;
92
+ var STATE_PADDING = 2;
93
+ var STATE_END = 3;
94
+ var STATE_GNU_LONG_PATH = 4;
95
+ var STATE_GNU_LONG_LINK = 5;
96
+ var STATE_PAX_HEADER = 6;
97
+ var STATE_SPARSE_EXTENDED = 7;
98
+ var STATE_SPARSE_DATA = 8;
99
+ var TarExtract = /*#__PURE__*/ function(EventEmitter) {
100
+ "use strict";
101
+ _inherits(TarExtract, EventEmitter);
102
+ function TarExtract(options) {
103
+ _class_call_check(this, TarExtract);
104
+ var _this;
105
+ _this = _call_super(this, TarExtract), // Current entry state
106
+ _this.header = null, _this.entryStream = null, _this.entryRemaining = 0, _this.paddingRemaining = 0, // Backpressure control
107
+ _this.locked = false, _this.pending = false, _this.finished = false, _this.finishEmitted = false, // Pending entry to emit (waiting for consumer to set up listeners)
108
+ _this.pendingEntry = null, // GNU/PAX extension data for next entry
109
+ _this.gnuLongPath = null, _this.gnuLongLink = null, _this.paxHeader = null, _this.paxGlobal = {}, _this.extensionData = [], _this.extensionRemaining = 0, // GNU sparse file state
110
+ _this.sparseInfo = null, _this.sparseStream = null, _this.sparseDataRemaining = 0;
111
+ _this.buffer = new _BufferListts.default();
112
+ _this.state = STATE_HEADER;
113
+ _this.options = options || {};
114
+ return _this;
115
+ }
116
+ var _proto = TarExtract.prototype;
117
+ /**
118
+ * Write data to the parser
119
+ */ _proto.write = function write(chunk, callback) {
120
+ if (this.finished) {
121
+ if (callback) callback();
122
+ return false;
123
+ }
124
+ this.buffer.append(chunk);
125
+ this._process();
126
+ // Emit any pending entry that was parsed during _process()
127
+ // This is necessary because _process() may parse new entry headers
128
+ // from incoming data, and those entries need to be emitted to listeners
129
+ this.resume();
130
+ if (callback) callback();
131
+ return !this.locked;
132
+ };
133
+ /**
134
+ * Signal end of input
135
+ */ _proto.end = function end(callback) {
136
+ this.finished = true;
137
+ this._process();
138
+ // Emit any pending entry before checking for finish
139
+ this.resume();
140
+ this._maybeFinish();
141
+ if (callback) callback();
142
+ };
143
+ /**
144
+ * Emit error to the main stream and any active entry stream
145
+ * This prevents tests from hanging when errors occur mid-extraction
146
+ */ _proto._emitError = function _emitError(err) {
147
+ // Propagate error to any active entry stream first
148
+ var activeStream = this.entryStream || this.sparseStream;
149
+ if (activeStream && !activeStream.ended) {
150
+ activeStream.emit('error', err);
151
+ }
152
+ // Then emit to the main extract stream
153
+ this.emit('error', err);
154
+ };
155
+ /**
156
+ * Emit 'finish' if appropriate
157
+ */ _proto._maybeFinish = function _maybeFinish() {
158
+ // Don't emit finish more than once
159
+ if (this.finishEmitted) return;
160
+ // Don't emit finish if we have a pending entry
161
+ if (this.pendingEntry) return;
162
+ // Don't emit finish if not finished yet
163
+ if (!this.finished) return;
164
+ // Don't emit finish if locked - consumer hasn't called next() yet
165
+ // and there may be more entries to process
166
+ if (this.locked) return;
167
+ // Only emit finish when we're in a terminal state
168
+ if (this.state === STATE_HEADER || this.state === STATE_END) {
169
+ this.state = STATE_END; // Mark as ended
170
+ this.finishEmitted = true;
171
+ this.emit('finish');
172
+ }
173
+ };
174
+ /**
175
+ * Resume parsing - emit any pending entry
176
+ * Call this after setting up 'entry' listeners
177
+ */ _proto.resume = function resume() {
178
+ // Only emit if there are listeners - this prevents entries from being
179
+ // lost when resume() is called from write() before listeners are set up
180
+ // Use listeners().length for Node 0.8 compatibility (listenerCount added in 0.10)
181
+ if (this.pendingEntry && this.listeners('entry').length > 0) {
182
+ var entry = this.pendingEntry;
183
+ this.pendingEntry = null;
184
+ // Clear pending flag so file data can flow
185
+ this.pending = false;
186
+ // Emit the entry
187
+ this.emit('entry', entry.header, entry.stream, entry.next);
188
+ // Continue processing file data
189
+ this._process();
190
+ // Check if we should emit finish now
191
+ this._maybeFinish();
192
+ }
193
+ };
194
+ /**
195
+ * Process buffered data through state machine
196
+ */ _proto._process = function _process() {
197
+ // Note: locked/pending only blocks processing NEXT header, not current entry data
198
+ if (this.pending) return;
199
+ var cont = true;
200
+ while(cont){
201
+ switch(this.state){
202
+ case STATE_HEADER:
203
+ // Don't process new headers while locked
204
+ if (this.locked) {
205
+ cont = false;
206
+ } else {
207
+ cont = this._processHeader();
208
+ }
209
+ break;
210
+ case STATE_FILE_DATA:
211
+ cont = this._processFileData();
212
+ break;
213
+ case STATE_PADDING:
214
+ cont = this._processPadding();
215
+ break;
216
+ case STATE_GNU_LONG_PATH:
217
+ case STATE_GNU_LONG_LINK:
218
+ case STATE_PAX_HEADER:
219
+ cont = this._processExtensionData();
220
+ break;
221
+ case STATE_SPARSE_EXTENDED:
222
+ cont = this._processSparseExtended();
223
+ break;
224
+ case STATE_SPARSE_DATA:
225
+ cont = this._processSparseData();
226
+ break;
227
+ case STATE_END:
228
+ cont = false;
229
+ break;
230
+ default:
231
+ cont = false;
232
+ }
233
+ }
234
+ };
235
+ /**
236
+ * Process header state
237
+ */ _proto._processHeader = function _processHeader() {
238
+ if (!this.buffer.has(_constantsts.HEADER_SIZE)) {
239
+ return false; // Need more data
240
+ }
241
+ var headerBuf = this.buffer.consume(_constantsts.HEADER_SIZE);
242
+ // Try to parse header
243
+ var header;
244
+ try {
245
+ header = (0, _headersts.parseHeader)(headerBuf, this.options);
246
+ } catch (err) {
247
+ this._emitError(err);
248
+ this.state = STATE_END;
249
+ return false;
250
+ }
251
+ // Null header means end of archive (empty block)
252
+ if (header === null) {
253
+ this.state = STATE_END;
254
+ this.emit('finish');
255
+ return false;
256
+ }
257
+ this.header = header;
258
+ this.paddingRemaining = (0, _headersts.overflow)(header.size);
259
+ // Handle GNU/PAX extension headers - collect data silently
260
+ if (header.type === 'gnu-long-path') {
261
+ this.extensionRemaining = header.size;
262
+ this.extensionData = [];
263
+ this.state = STATE_GNU_LONG_PATH;
264
+ return true; // Continue processing
265
+ }
266
+ if (header.type === 'gnu-long-link-path') {
267
+ this.extensionRemaining = header.size;
268
+ this.extensionData = [];
269
+ this.state = STATE_GNU_LONG_LINK;
270
+ return true; // Continue processing
271
+ }
272
+ if (header.type === 'pax-header') {
273
+ this.extensionRemaining = header.size;
274
+ this.extensionData = [];
275
+ this.state = STATE_PAX_HEADER;
276
+ return true; // Continue processing
277
+ }
278
+ if (header.type === 'pax-global-header') {
279
+ // For global headers, we read them but they apply to all subsequent entries
280
+ this.extensionRemaining = header.size;
281
+ this.extensionData = [];
282
+ this.state = STATE_PAX_HEADER; // Same handling, different application
283
+ return true; // Continue processing
284
+ }
285
+ // Handle GNU sparse files
286
+ if (header.type === 'gnu-sparse') {
287
+ // Parse sparse info from header
288
+ this.sparseInfo = (0, _sparsets.parseGnuSparseHeader)(headerBuf);
289
+ // Apply extensions (e.g., GNU long path)
290
+ this._applyExtensions(header);
291
+ // Update header size to real (reconstructed) file size
292
+ header.size = this.sparseInfo.realSize;
293
+ // If extended sparse headers follow, read them first
294
+ if (this.sparseInfo.isExtended) {
295
+ this.header = header;
296
+ this.state = STATE_SPARSE_EXTENDED;
297
+ return true; // Continue processing
298
+ }
299
+ // No extended headers - set up sparse entry now
300
+ return this._setupSparseEntry(header);
301
+ }
302
+ // Apply any pending GNU/PAX extensions to this entry
303
+ this._applyExtensions(header);
304
+ // Set up for file data
305
+ this.entryRemaining = header.size;
306
+ // Create entry stream
307
+ this.entryStream = new _EntryStreamts.default();
308
+ // Lock until consumer calls next()
309
+ this.locked = true;
310
+ this.pending = true;
311
+ // Store pending entry (will be emitted when consumer calls resume())
312
+ var self = this;
313
+ var entryStream = this.entryStream;
314
+ var next = function next() {
315
+ self._unlock();
316
+ };
317
+ this.pendingEntry = {
318
+ header: header,
319
+ stream: entryStream,
320
+ next: next
321
+ };
322
+ // If no data, go straight to padding
323
+ if (this.entryRemaining === 0) {
324
+ this.entryStream.end();
325
+ this.entryStream = null;
326
+ this.state = this.paddingRemaining > 0 ? STATE_PADDING : STATE_HEADER;
327
+ } else {
328
+ this.state = STATE_FILE_DATA;
329
+ }
330
+ return false; // Don't continue processing until unlocked
331
+ };
332
+ /**
333
+ * Apply pending GNU/PAX extensions to a header
334
+ */ _proto._applyExtensions = function _applyExtensions(header) {
335
+ // Apply PAX global header first
336
+ if (this.paxGlobal) {
337
+ this._applyPaxToHeader(header, this.paxGlobal);
338
+ }
339
+ // Apply PAX header (per-entry, overrides global)
340
+ if (this.paxHeader) {
341
+ this._applyPaxToHeader(header, this.paxHeader);
342
+ header.pax = this.paxHeader;
343
+ this.paxHeader = null;
344
+ }
345
+ // Apply GNU long path (overrides PAX path)
346
+ if (this.gnuLongPath !== null) {
347
+ header.name = this.gnuLongPath;
348
+ this.gnuLongPath = null;
349
+ }
350
+ // Apply GNU long link (overrides PAX linkpath)
351
+ if (this.gnuLongLink !== null) {
352
+ header.linkname = this.gnuLongLink;
353
+ this.gnuLongLink = null;
354
+ }
355
+ };
356
+ /**
357
+ * Apply PAX attributes to header
358
+ */ _proto._applyPaxToHeader = function _applyPaxToHeader(header, pax) {
359
+ if (pax.path) header.name = pax.path;
360
+ if (pax.linkpath) header.linkname = pax.linkpath;
361
+ if (pax.size) header.size = parseInt(pax.size, 10);
362
+ if (pax.uid) header.uid = parseInt(pax.uid, 10);
363
+ if (pax.gid) header.gid = parseInt(pax.gid, 10);
364
+ if (pax.uname) header.uname = pax.uname;
365
+ if (pax.gname) header.gname = pax.gname;
366
+ if (pax.mtime) header.mtime = new Date(parseFloat(pax.mtime) * 1000);
367
+ };
368
+ /**
369
+ * Process extension data (GNU long path/link, PAX headers)
370
+ */ _proto._processExtensionData = function _processExtensionData() {
371
+ if (this.extensionRemaining <= 0) {
372
+ // Done collecting extension data - decode and store
373
+ this._finalizeExtension();
374
+ this.state = this.paddingRemaining > 0 ? STATE_PADDING : STATE_HEADER;
375
+ return true;
376
+ }
377
+ if (this.buffer.length === 0) {
378
+ return false; // Need more data
379
+ }
380
+ // Read as much as we can
381
+ var toRead = Math.min(this.extensionRemaining, this.buffer.length);
382
+ var data = this.buffer.consume(toRead);
383
+ this.extensionRemaining -= toRead;
384
+ this.extensionData.push(data);
385
+ // Check if done
386
+ if (this.extensionRemaining <= 0) {
387
+ this._finalizeExtension();
388
+ this.state = this.paddingRemaining > 0 ? STATE_PADDING : STATE_HEADER;
389
+ }
390
+ return true;
391
+ };
392
+ /**
393
+ * Finalize extension data collection
394
+ */ _proto._finalizeExtension = function _finalizeExtension() {
395
+ // Concatenate all collected data
396
+ var totalLength = this.extensionData.reduce(function(sum, buf) {
397
+ return sum + buf.length;
398
+ }, 0);
399
+ var combined = Buffer.concat ? Buffer.concat(this.extensionData, totalLength) : this._concatBuffers(this.extensionData, totalLength);
400
+ this.extensionData = [];
401
+ var encoding = this.options.filenameEncoding || 'utf8';
402
+ switch(this.state){
403
+ case STATE_GNU_LONG_PATH:
404
+ this.gnuLongPath = (0, _headersts.decodeLongPath)(combined, encoding);
405
+ break;
406
+ case STATE_GNU_LONG_LINK:
407
+ this.gnuLongLink = (0, _headersts.decodeLongPath)(combined, encoding);
408
+ break;
409
+ case STATE_PAX_HEADER:
410
+ // Check if this was a global header
411
+ if (this.header && this.header.type === 'pax-global-header') {
412
+ var global = (0, _headersts.decodePax)(combined);
413
+ // Merge into global (don't replace, merge)
414
+ for(var key in global){
415
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: ES2021 compatibility
416
+ if (global.hasOwnProperty(key)) {
417
+ this.paxGlobal[key] = global[key];
418
+ }
419
+ }
420
+ } else {
421
+ this.paxHeader = (0, _headersts.decodePax)(combined);
422
+ }
423
+ break;
424
+ }
425
+ };
426
+ /**
427
+ * Concatenate buffers (Node 0.8 compatible fallback)
428
+ */ _proto._concatBuffers = function _concatBuffers(buffers, totalLength) {
429
+ var result = new Buffer(totalLength);
430
+ var offset = 0;
431
+ for(var i = 0; i < buffers.length; i++){
432
+ var buf = buffers[i];
433
+ buf.copy(result, offset);
434
+ offset += buf.length;
435
+ }
436
+ return result;
437
+ };
438
+ /**
439
+ * Process file data state
440
+ */ _proto._processFileData = function _processFileData() {
441
+ if (this.entryRemaining <= 0) {
442
+ // Done with file data
443
+ if (this.entryStream) {
444
+ this.entryStream.end();
445
+ this.entryStream = null;
446
+ }
447
+ this.state = this.paddingRemaining > 0 ? STATE_PADDING : STATE_HEADER;
448
+ return true;
449
+ }
450
+ if (this.buffer.length === 0) {
451
+ return false; // Need more data
452
+ }
453
+ // Read as much as we can
454
+ var toRead = Math.min(this.entryRemaining, this.buffer.length);
455
+ var data = this.buffer.consume(toRead);
456
+ this.entryRemaining -= toRead;
457
+ // Push to entry stream
458
+ if (this.entryStream) {
459
+ this.entryStream.push(data);
460
+ }
461
+ // Check if done
462
+ if (this.entryRemaining <= 0) {
463
+ if (this.entryStream) {
464
+ this.entryStream.end();
465
+ this.entryStream = null;
466
+ }
467
+ this.state = this.paddingRemaining > 0 ? STATE_PADDING : STATE_HEADER;
468
+ }
469
+ return true;
470
+ };
471
+ /**
472
+ * Process padding state
473
+ */ _proto._processPadding = function _processPadding() {
474
+ if (this.paddingRemaining <= 0) {
475
+ this.state = STATE_HEADER;
476
+ return true;
477
+ }
478
+ if (this.buffer.length === 0) {
479
+ return false; // Need more data
480
+ }
481
+ // Skip padding bytes
482
+ var toSkip = Math.min(this.paddingRemaining, this.buffer.length);
483
+ this.buffer.consume(toSkip);
484
+ this.paddingRemaining -= toSkip;
485
+ if (this.paddingRemaining <= 0) {
486
+ this.state = STATE_HEADER;
487
+ }
488
+ return true;
489
+ };
490
+ /**
491
+ * Unlock parser (called by next() callback)
492
+ */ _proto._unlock = function _unlock() {
493
+ this.locked = false;
494
+ this.pending = false;
495
+ this._process();
496
+ // After processing, if there's a pending entry, emit it
497
+ // (the consumer's listeners are still set up from previous entry)
498
+ this.resume();
499
+ // Check if we should emit finish (e.g., if end() was called while locked)
500
+ this._maybeFinish();
501
+ };
502
+ /**
503
+ * Set up a sparse entry with SparseStream
504
+ */ _proto._setupSparseEntry = function _setupSparseEntry(header) {
505
+ if (!this.sparseInfo) {
506
+ this._emitError(new Error('Sparse info not available'));
507
+ this.state = STATE_END;
508
+ return false;
509
+ }
510
+ // Calculate actual data size (sum of all sparse entry numbytes)
511
+ this.sparseDataRemaining = (0, _sparsets.sparseDataSize)(this.sparseInfo.entries);
512
+ // Calculate padding for the actual data size
513
+ this.paddingRemaining = (0, _headersts.overflow)(this.sparseDataRemaining);
514
+ // Create sparse stream for reconstruction
515
+ this.sparseStream = new _sparsets.SparseStream(this.sparseInfo.entries, this.sparseInfo.realSize);
516
+ // Lock until consumer calls next()
517
+ this.locked = true;
518
+ this.pending = true;
519
+ // Store pending entry (the stream looks like a regular entry to consumers)
520
+ var self = this;
521
+ var stream = this.sparseStream;
522
+ var next = function next() {
523
+ self._unlock();
524
+ };
525
+ // Change header type to 'file' for consumers (they don't need to know it's sparse)
526
+ header.type = 'file';
527
+ this.pendingEntry = {
528
+ header: header,
529
+ stream: stream,
530
+ next: next
531
+ };
532
+ // Go to sparse data state
533
+ if (this.sparseDataRemaining === 0) {
534
+ // No data - just holes (all zeros)
535
+ this.sparseStream.end();
536
+ this.sparseStream = null;
537
+ this.sparseInfo = null;
538
+ this.state = this.paddingRemaining > 0 ? STATE_PADDING : STATE_HEADER;
539
+ } else {
540
+ this.state = STATE_SPARSE_DATA;
541
+ }
542
+ return false; // Don't continue until unlocked
543
+ };
544
+ /**
545
+ * Process extended sparse headers
546
+ */ _proto._processSparseExtended = function _processSparseExtended() {
547
+ if (!this.buffer.has(_constantsts.BLOCK_SIZE)) {
548
+ return false; // Need more data
549
+ }
550
+ var extBuf = this.buffer.consume(_constantsts.BLOCK_SIZE);
551
+ var ext = (0, _sparsets.parseGnuSparseExtended)(extBuf);
552
+ // Add entries to sparse info
553
+ if (this.sparseInfo) {
554
+ for(var i = 0; i < ext.entries.length; i++){
555
+ this.sparseInfo.entries.push(ext.entries[i]);
556
+ }
557
+ // Check if more extended headers follow
558
+ if (ext.isExtended) {
559
+ return true; // Continue reading extended headers
560
+ }
561
+ }
562
+ // Done reading extended headers - set up the sparse entry
563
+ if (this.header) {
564
+ return this._setupSparseEntry(this.header);
565
+ }
566
+ // Should not reach here
567
+ this._emitError(new Error('Header not available for sparse entry'));
568
+ this.state = STATE_END;
569
+ return false;
570
+ };
571
+ /**
572
+ * Process sparse file data
573
+ */ _proto._processSparseData = function _processSparseData() {
574
+ if (this.sparseDataRemaining <= 0) {
575
+ // Done with sparse data
576
+ if (this.sparseStream) {
577
+ this.sparseStream.end();
578
+ this.sparseStream = null;
579
+ }
580
+ this.sparseInfo = null;
581
+ this.state = this.paddingRemaining > 0 ? STATE_PADDING : STATE_HEADER;
582
+ return true;
583
+ }
584
+ if (this.buffer.length === 0) {
585
+ return false; // Need more data
586
+ }
587
+ // Read as much as we can
588
+ var toRead = Math.min(this.sparseDataRemaining, this.buffer.length);
589
+ var data = this.buffer.consume(toRead);
590
+ this.sparseDataRemaining -= toRead;
591
+ // Push to sparse stream for reconstruction
592
+ if (this.sparseStream) {
593
+ this.sparseStream.push(data);
594
+ }
595
+ // Check if done
596
+ if (this.sparseDataRemaining <= 0) {
597
+ if (this.sparseStream) {
598
+ this.sparseStream.end();
599
+ this.sparseStream = null;
600
+ }
601
+ this.sparseInfo = null;
602
+ this.state = this.paddingRemaining > 0 ? STATE_PADDING : STATE_HEADER;
603
+ }
604
+ return true;
605
+ };
606
+ return TarExtract;
607
+ }(_events.EventEmitter);
608
+ /* 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; }