tar-iterator 2.2.9 → 3.0.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.js +1 -1
- package/dist/cjs/FileEntry.js.map +1 -1
- package/dist/cjs/TarIterator.d.cts +4 -1
- package/dist/cjs/TarIterator.d.ts +4 -1
- package/dist/cjs/TarIterator.js +19 -46
- package/dist/cjs/TarIterator.js.map +1 -1
- package/dist/cjs/index.d.cts +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +12 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/nextEntry.js +27 -10
- package/dist/cjs/nextEntry.js.map +1 -1
- package/dist/cjs/tar/BufferList.d.cts +31 -0
- package/dist/cjs/tar/BufferList.d.ts +31 -0
- package/dist/cjs/tar/BufferList.js +104 -0
- package/dist/cjs/tar/BufferList.js.map +1 -0
- package/dist/cjs/tar/EntryStream.d.cts +4 -0
- package/dist/cjs/tar/EntryStream.d.ts +4 -0
- package/dist/cjs/tar/EntryStream.js +22 -0
- package/dist/cjs/tar/EntryStream.js.map +1 -0
- package/dist/cjs/tar/TarExtract.d.cts +125 -0
- package/dist/cjs/tar/TarExtract.d.ts +125 -0
- package/dist/cjs/tar/TarExtract.js +608 -0
- package/dist/cjs/tar/TarExtract.js.map +1 -0
- package/dist/cjs/tar/constants.d.cts +70 -0
- package/dist/cjs/tar/constants.d.ts +70 -0
- package/dist/cjs/tar/constants.js +288 -0
- package/dist/cjs/tar/constants.js.map +1 -0
- package/dist/cjs/tar/errors.d.cts +28 -0
- package/dist/cjs/tar/errors.d.ts +28 -0
- package/dist/cjs/tar/errors.js +34 -0
- package/dist/cjs/tar/errors.js.map +1 -0
- package/dist/cjs/tar/headers.d.cts +81 -0
- package/dist/cjs/tar/headers.d.ts +81 -0
- package/dist/cjs/tar/headers.js +285 -0
- package/dist/cjs/tar/headers.js.map +1 -0
- package/dist/cjs/tar/index.d.cts +9 -0
- package/dist/cjs/tar/index.d.ts +9 -0
- package/dist/cjs/tar/index.js +45 -0
- package/dist/cjs/tar/index.js.map +1 -0
- package/dist/cjs/tar/sparse.d.cts +91 -0
- package/dist/cjs/tar/sparse.d.ts +91 -0
- package/dist/cjs/tar/sparse.js +269 -0
- package/dist/cjs/tar/sparse.js.map +1 -0
- package/dist/esm/FileEntry.js +1 -1
- package/dist/esm/FileEntry.js.map +1 -1
- package/dist/esm/TarIterator.d.ts +4 -1
- package/dist/esm/TarIterator.js +20 -4
- package/dist/esm/TarIterator.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/nextEntry.js +27 -10
- package/dist/esm/nextEntry.js.map +1 -1
- package/dist/esm/tar/BufferList.d.ts +31 -0
- package/dist/esm/tar/BufferList.js +85 -0
- package/dist/esm/tar/BufferList.js.map +1 -0
- package/dist/esm/tar/EntryStream.d.ts +4 -0
- package/dist/esm/tar/EntryStream.js +3 -0
- package/dist/esm/tar/EntryStream.js.map +1 -0
- package/dist/esm/tar/TarExtract.d.ts +125 -0
- package/dist/esm/tar/TarExtract.js +538 -0
- package/dist/esm/tar/TarExtract.js.map +1 -0
- package/dist/esm/tar/constants.d.ts +70 -0
- package/dist/esm/tar/constants.js +100 -0
- package/dist/esm/tar/constants.js.map +1 -0
- package/dist/esm/tar/errors.d.ts +28 -0
- package/dist/esm/tar/errors.js +23 -0
- package/dist/esm/tar/errors.js.map +1 -0
- package/dist/esm/tar/headers.d.ts +81 -0
- package/dist/esm/tar/headers.js +271 -0
- package/dist/esm/tar/headers.js.map +1 -0
- package/dist/esm/tar/index.d.ts +9 -0
- package/dist/esm/tar/index.js +8 -0
- package/dist/esm/tar/index.js.map +1 -0
- package/dist/esm/tar/sparse.d.ts +91 -0
- package/dist/esm/tar/sparse.js +172 -0
- package/dist/esm/tar/sparse.js.map +1 -0
- package/package.json +7 -8
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GNU Sparse File Support
|
|
3
|
+
*
|
|
4
|
+
* Handles parsing of GNU sparse file headers and stream reconstruction.
|
|
5
|
+
*
|
|
6
|
+
* GNU sparse format stores:
|
|
7
|
+
* 1. A sparse map in the header (offset 386) with up to 4 entries
|
|
8
|
+
* 2. Extended sparse headers (512-byte blocks) if more entries needed
|
|
9
|
+
* 3. The actual data chunks (only non-zero portions of the file)
|
|
10
|
+
*
|
|
11
|
+
* Each sparse entry contains:
|
|
12
|
+
* - offset: position in the virtual file where this data chunk belongs
|
|
13
|
+
* - numbytes: size of this data chunk
|
|
14
|
+
*
|
|
15
|
+
* Node 0.8 compatible - uses only basic Buffer operations.
|
|
16
|
+
*/
|
|
17
|
+
import EntryStream from './EntryStream.js';
|
|
18
|
+
/**
|
|
19
|
+
* Represents a region of actual data in a sparse file
|
|
20
|
+
*/
|
|
21
|
+
export interface SparseEntry {
|
|
22
|
+
/** Offset in the reconstructed (virtual) file */
|
|
23
|
+
offset: number;
|
|
24
|
+
/** Number of bytes of actual data */
|
|
25
|
+
numbytes: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parsed sparse header information
|
|
29
|
+
*/
|
|
30
|
+
export interface SparseInfo {
|
|
31
|
+
/** The actual (reconstructed) file size */
|
|
32
|
+
realSize: number;
|
|
33
|
+
/** Sparse map entries */
|
|
34
|
+
entries: SparseEntry[];
|
|
35
|
+
/** Whether there are more entries in extended headers */
|
|
36
|
+
isExtended: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Parse GNU sparse header information from a tar header block
|
|
40
|
+
*
|
|
41
|
+
* @param headerBuf - The 512-byte tar header buffer
|
|
42
|
+
* @returns Sparse info including real size, entries, and extended flag
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseGnuSparseHeader(headerBuf: Buffer): SparseInfo;
|
|
45
|
+
/**
|
|
46
|
+
* Parse GNU sparse extended header block
|
|
47
|
+
*
|
|
48
|
+
* @param extBuf - The 512-byte extended sparse header buffer
|
|
49
|
+
* @returns Object with entries and whether more extended blocks follow
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseGnuSparseExtended(extBuf: Buffer): {
|
|
52
|
+
entries: SparseEntry[];
|
|
53
|
+
isExtended: boolean;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Calculate total data size from sparse map
|
|
57
|
+
* This is the actual size of data stored in the archive (sum of all numbytes)
|
|
58
|
+
*/
|
|
59
|
+
export declare function sparseDataSize(entries: SparseEntry[]): number;
|
|
60
|
+
/**
|
|
61
|
+
* Stream that reconstructs a sparse file from data chunks
|
|
62
|
+
*
|
|
63
|
+
* Takes the sparse map and actual data, outputs reconstructed file
|
|
64
|
+
* with zeros inserted for holes.
|
|
65
|
+
*
|
|
66
|
+
* Extends EntryStream to inherit pause/resume/pipe behavior.
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
export declare class SparseStream extends EntryStream {
|
|
71
|
+
private entries;
|
|
72
|
+
private realSize;
|
|
73
|
+
private currentEntry;
|
|
74
|
+
private virtualPosition;
|
|
75
|
+
private entryBytesRemaining;
|
|
76
|
+
constructor(entries: SparseEntry[], realSize: number);
|
|
77
|
+
/**
|
|
78
|
+
* Push data from the tar archive (actual sparse data chunk)
|
|
79
|
+
* Overrides EntryStream.push() to reconstruct sparse file with holes.
|
|
80
|
+
*/
|
|
81
|
+
push(data: Buffer): void;
|
|
82
|
+
/**
|
|
83
|
+
* End the stream - emit any trailing zeros
|
|
84
|
+
* Overrides EntryStream.end() to emit trailing zeros first.
|
|
85
|
+
*/
|
|
86
|
+
end(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Emit zeros for a hole, reusing the shared zero buffer
|
|
89
|
+
*/
|
|
90
|
+
private _emitZeros;
|
|
91
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GNU Sparse File Support
|
|
3
|
+
*
|
|
4
|
+
* Handles parsing of GNU sparse file headers and stream reconstruction.
|
|
5
|
+
*
|
|
6
|
+
* GNU sparse format stores:
|
|
7
|
+
* 1. A sparse map in the header (offset 386) with up to 4 entries
|
|
8
|
+
* 2. Extended sparse headers (512-byte blocks) if more entries needed
|
|
9
|
+
* 3. The actual data chunks (only non-zero portions of the file)
|
|
10
|
+
*
|
|
11
|
+
* Each sparse entry contains:
|
|
12
|
+
* - offset: position in the virtual file where this data chunk belongs
|
|
13
|
+
* - numbytes: size of this data chunk
|
|
14
|
+
*
|
|
15
|
+
* Node 0.8 compatible - uses only basic Buffer operations.
|
|
16
|
+
*/ "use strict";
|
|
17
|
+
Object.defineProperty(exports, "__esModule", {
|
|
18
|
+
value: true
|
|
19
|
+
});
|
|
20
|
+
function _export(target, all) {
|
|
21
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
_export(exports, {
|
|
27
|
+
get SparseStream () {
|
|
28
|
+
return SparseStream;
|
|
29
|
+
},
|
|
30
|
+
get parseGnuSparseExtended () {
|
|
31
|
+
return parseGnuSparseExtended;
|
|
32
|
+
},
|
|
33
|
+
get parseGnuSparseHeader () {
|
|
34
|
+
return parseGnuSparseHeader;
|
|
35
|
+
},
|
|
36
|
+
get sparseDataSize () {
|
|
37
|
+
return sparseDataSize;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
var _constantsts = require("./constants.js");
|
|
41
|
+
var _EntryStreamts = /*#__PURE__*/ _interop_require_default(require("./EntryStream.js"));
|
|
42
|
+
var _headersts = require("./headers.js");
|
|
43
|
+
function _assert_this_initialized(self) {
|
|
44
|
+
if (self === void 0) {
|
|
45
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
46
|
+
}
|
|
47
|
+
return self;
|
|
48
|
+
}
|
|
49
|
+
function _call_super(_this, derived, args) {
|
|
50
|
+
derived = _get_prototype_of(derived);
|
|
51
|
+
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
|
|
52
|
+
}
|
|
53
|
+
function _class_call_check(instance, Constructor) {
|
|
54
|
+
if (!(instance instanceof Constructor)) {
|
|
55
|
+
throw new TypeError("Cannot call a class as a function");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function _get(target, property, receiver) {
|
|
59
|
+
if (typeof Reflect !== "undefined" && Reflect.get) {
|
|
60
|
+
_get = Reflect.get;
|
|
61
|
+
} else {
|
|
62
|
+
_get = function get(target, property, receiver) {
|
|
63
|
+
var base = _super_prop_base(target, property);
|
|
64
|
+
if (!base) return;
|
|
65
|
+
var desc = Object.getOwnPropertyDescriptor(base, property);
|
|
66
|
+
if (desc.get) {
|
|
67
|
+
return desc.get.call(receiver || target);
|
|
68
|
+
}
|
|
69
|
+
return desc.value;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return _get(target, property, receiver || target);
|
|
73
|
+
}
|
|
74
|
+
function _get_prototype_of(o) {
|
|
75
|
+
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
76
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
77
|
+
};
|
|
78
|
+
return _get_prototype_of(o);
|
|
79
|
+
}
|
|
80
|
+
function _inherits(subClass, superClass) {
|
|
81
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
82
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
83
|
+
}
|
|
84
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
85
|
+
constructor: {
|
|
86
|
+
value: subClass,
|
|
87
|
+
writable: true,
|
|
88
|
+
configurable: true
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
if (superClass) _set_prototype_of(subClass, superClass);
|
|
92
|
+
}
|
|
93
|
+
function _interop_require_default(obj) {
|
|
94
|
+
return obj && obj.__esModule ? obj : {
|
|
95
|
+
default: obj
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function _possible_constructor_return(self, call) {
|
|
99
|
+
if (call && (_type_of(call) === "object" || typeof call === "function")) {
|
|
100
|
+
return call;
|
|
101
|
+
}
|
|
102
|
+
return _assert_this_initialized(self);
|
|
103
|
+
}
|
|
104
|
+
function _set_prototype_of(o, p) {
|
|
105
|
+
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
|
|
106
|
+
o.__proto__ = p;
|
|
107
|
+
return o;
|
|
108
|
+
};
|
|
109
|
+
return _set_prototype_of(o, p);
|
|
110
|
+
}
|
|
111
|
+
function _super_prop_base(object, property) {
|
|
112
|
+
while(!Object.prototype.hasOwnProperty.call(object, property)){
|
|
113
|
+
object = _get_prototype_of(object);
|
|
114
|
+
if (object === null) break;
|
|
115
|
+
}
|
|
116
|
+
return object;
|
|
117
|
+
}
|
|
118
|
+
function _type_of(obj) {
|
|
119
|
+
"@swc/helpers - typeof";
|
|
120
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
121
|
+
}
|
|
122
|
+
function _is_native_reflect_construct() {
|
|
123
|
+
try {
|
|
124
|
+
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
125
|
+
} catch (_) {}
|
|
126
|
+
return (_is_native_reflect_construct = function() {
|
|
127
|
+
return !!result;
|
|
128
|
+
})();
|
|
129
|
+
}
|
|
130
|
+
// Reusable zero buffer for sparse hole emission (64KB)
|
|
131
|
+
var ZERO_BUFFER_SIZE = 65536;
|
|
132
|
+
var zeroBuffer = null;
|
|
133
|
+
function getZeroBuffer() {
|
|
134
|
+
if (!zeroBuffer) {
|
|
135
|
+
zeroBuffer = new Buffer(ZERO_BUFFER_SIZE);
|
|
136
|
+
for(var i = 0; i < ZERO_BUFFER_SIZE; i++){
|
|
137
|
+
zeroBuffer[i] = 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return zeroBuffer;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Parse sparse entries from a buffer starting at given offset
|
|
144
|
+
*
|
|
145
|
+
* @param buf - Buffer containing sparse entries
|
|
146
|
+
* @param startOffset - Offset in buffer where entries begin
|
|
147
|
+
* @param maxEntries - Maximum number of entries to read
|
|
148
|
+
* @returns Array of valid sparse entries (stops at first zero entry)
|
|
149
|
+
*/ function parseSparseEntries(buf, startOffset, maxEntries) {
|
|
150
|
+
var entries = [];
|
|
151
|
+
for(var i = 0; i < maxEntries; i++){
|
|
152
|
+
var entryOffset = startOffset + i * _constantsts.SPARSE_ENTRY_SIZE;
|
|
153
|
+
var offset = (0, _headersts.decodeOct)(buf, entryOffset, _constantsts.SPARSE_ENTRY_OFFSET_SIZE);
|
|
154
|
+
var numbytes = (0, _headersts.decodeOct)(buf, entryOffset + _constantsts.SPARSE_ENTRY_OFFSET_SIZE, _constantsts.SPARSE_ENTRY_NUMBYTES_SIZE);
|
|
155
|
+
// Stop at first zero entry (end of sparse map)
|
|
156
|
+
if (offset === 0 && numbytes === 0) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
entries.push({
|
|
160
|
+
offset: offset,
|
|
161
|
+
numbytes: numbytes
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return entries;
|
|
165
|
+
}
|
|
166
|
+
function parseGnuSparseHeader(headerBuf) {
|
|
167
|
+
// Parse sparse entries from header (up to 4)
|
|
168
|
+
var entries = parseSparseEntries(headerBuf, _constantsts.SPARSE_OFFSET, _constantsts.SPARSE_ENTRIES_IN_HEADER);
|
|
169
|
+
// Parse isextended flag
|
|
170
|
+
var isExtended = headerBuf[_constantsts.SPARSE_ISEXTENDED_OFFSET] !== 0;
|
|
171
|
+
// Parse real file size
|
|
172
|
+
var realSize = (0, _headersts.decodeOct)(headerBuf, _constantsts.SPARSE_REALSIZE_OFFSET, _constantsts.SPARSE_REALSIZE_SIZE);
|
|
173
|
+
return {
|
|
174
|
+
realSize: realSize,
|
|
175
|
+
entries: entries,
|
|
176
|
+
isExtended: isExtended
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function parseGnuSparseExtended(extBuf) {
|
|
180
|
+
// Parse sparse entries from extended block (up to 21)
|
|
181
|
+
var entries = parseSparseEntries(extBuf, 0, _constantsts.SPARSE_EXTENDED_ENTRIES);
|
|
182
|
+
// Parse isextended flag
|
|
183
|
+
var isExtended = extBuf[_constantsts.SPARSE_EXTENDED_ISEXTENDED_OFFSET] !== 0;
|
|
184
|
+
return {
|
|
185
|
+
entries: entries,
|
|
186
|
+
isExtended: isExtended
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function sparseDataSize(entries) {
|
|
190
|
+
var total = 0;
|
|
191
|
+
for(var i = 0; i < entries.length; i++){
|
|
192
|
+
total += entries[i].numbytes;
|
|
193
|
+
}
|
|
194
|
+
return total;
|
|
195
|
+
}
|
|
196
|
+
var SparseStream = /*#__PURE__*/ function(EntryStream) {
|
|
197
|
+
"use strict";
|
|
198
|
+
_inherits(SparseStream, EntryStream);
|
|
199
|
+
function SparseStream(entries, realSize) {
|
|
200
|
+
_class_call_check(this, SparseStream);
|
|
201
|
+
var _this;
|
|
202
|
+
_this = _call_super(this, SparseStream);
|
|
203
|
+
_this.entries = entries;
|
|
204
|
+
_this.realSize = realSize;
|
|
205
|
+
_this.currentEntry = 0;
|
|
206
|
+
_this.virtualPosition = 0;
|
|
207
|
+
_this.entryBytesRemaining = entries.length > 0 ? entries[0].numbytes : 0;
|
|
208
|
+
return _this;
|
|
209
|
+
}
|
|
210
|
+
var _proto = SparseStream.prototype;
|
|
211
|
+
/**
|
|
212
|
+
* Push data from the tar archive (actual sparse data chunk)
|
|
213
|
+
* Overrides EntryStream.push() to reconstruct sparse file with holes.
|
|
214
|
+
*/ _proto.push = function push(data) {
|
|
215
|
+
if (this.ended) return;
|
|
216
|
+
var dataOffset = 0;
|
|
217
|
+
while(dataOffset < data.length && this.currentEntry < this.entries.length){
|
|
218
|
+
var entry = this.entries[this.currentEntry];
|
|
219
|
+
// First, emit zeros for any hole before current entry
|
|
220
|
+
if (this.virtualPosition < entry.offset) {
|
|
221
|
+
var holeSize = entry.offset - this.virtualPosition;
|
|
222
|
+
this._emitZeros(holeSize);
|
|
223
|
+
this.virtualPosition = entry.offset;
|
|
224
|
+
}
|
|
225
|
+
// Now emit actual data for this entry
|
|
226
|
+
var toEmit = Math.min(this.entryBytesRemaining, data.length - dataOffset);
|
|
227
|
+
if (toEmit > 0) {
|
|
228
|
+
var chunk = data.slice(dataOffset, dataOffset + toEmit);
|
|
229
|
+
_get(_get_prototype_of(SparseStream.prototype), "push", this).call(this, chunk);
|
|
230
|
+
dataOffset += toEmit;
|
|
231
|
+
this.virtualPosition += toEmit;
|
|
232
|
+
this.entryBytesRemaining -= toEmit;
|
|
233
|
+
}
|
|
234
|
+
// Move to next entry if current is exhausted
|
|
235
|
+
if (this.entryBytesRemaining <= 0) {
|
|
236
|
+
this.currentEntry++;
|
|
237
|
+
if (this.currentEntry < this.entries.length) {
|
|
238
|
+
this.entryBytesRemaining = this.entries[this.currentEntry].numbytes;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* End the stream - emit any trailing zeros
|
|
245
|
+
* Overrides EntryStream.end() to emit trailing zeros first.
|
|
246
|
+
*/ _proto.end = function end() {
|
|
247
|
+
if (this.ended) return;
|
|
248
|
+
// Emit remaining zeros to reach real file size
|
|
249
|
+
if (this.virtualPosition < this.realSize) {
|
|
250
|
+
this._emitZeros(this.realSize - this.virtualPosition);
|
|
251
|
+
this.virtualPosition = this.realSize;
|
|
252
|
+
}
|
|
253
|
+
_get(_get_prototype_of(SparseStream.prototype), "end", this).call(this);
|
|
254
|
+
};
|
|
255
|
+
/**
|
|
256
|
+
* Emit zeros for a hole, reusing the shared zero buffer
|
|
257
|
+
*/ _proto._emitZeros = function _emitZeros(size) {
|
|
258
|
+
var zeros = getZeroBuffer();
|
|
259
|
+
var remaining = size;
|
|
260
|
+
while(remaining > 0){
|
|
261
|
+
var toEmit = Math.min(remaining, ZERO_BUFFER_SIZE);
|
|
262
|
+
// Slice from the reusable buffer to emit exact size needed
|
|
263
|
+
_get(_get_prototype_of(SparseStream.prototype), "push", this).call(this, zeros.slice(0, toEmit));
|
|
264
|
+
remaining -= toEmit;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
return SparseStream;
|
|
268
|
+
}(_EntryStreamts.default);
|
|
269
|
+
/* 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; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/tar/sparse.ts"],"sourcesContent":["/**\n * GNU Sparse File Support\n *\n * Handles parsing of GNU sparse file headers and stream reconstruction.\n *\n * GNU sparse format stores:\n * 1. A sparse map in the header (offset 386) with up to 4 entries\n * 2. Extended sparse headers (512-byte blocks) if more entries needed\n * 3. The actual data chunks (only non-zero portions of the file)\n *\n * Each sparse entry contains:\n * - offset: position in the virtual file where this data chunk belongs\n * - numbytes: size of this data chunk\n *\n * Node 0.8 compatible - uses only basic Buffer operations.\n */\n\nimport { SPARSE_ENTRIES_IN_HEADER, SPARSE_ENTRY_NUMBYTES_SIZE, SPARSE_ENTRY_OFFSET_SIZE, SPARSE_ENTRY_SIZE, SPARSE_EXTENDED_ENTRIES, SPARSE_EXTENDED_ISEXTENDED_OFFSET, SPARSE_ISEXTENDED_OFFSET, SPARSE_OFFSET, SPARSE_REALSIZE_OFFSET, SPARSE_REALSIZE_SIZE } from './constants.ts';\nimport EntryStream from './EntryStream.ts';\nimport { decodeOct } from './headers.ts';\n\n// Reusable zero buffer for sparse hole emission (64KB)\nconst ZERO_BUFFER_SIZE = 65536;\nlet zeroBuffer: Buffer | null = null;\n\nfunction getZeroBuffer(): Buffer {\n if (!zeroBuffer) {\n zeroBuffer = new Buffer(ZERO_BUFFER_SIZE);\n for (let i = 0; i < ZERO_BUFFER_SIZE; i++) {\n zeroBuffer[i] = 0;\n }\n }\n return zeroBuffer;\n}\n\n/**\n * Represents a region of actual data in a sparse file\n */\nexport interface SparseEntry {\n /** Offset in the reconstructed (virtual) file */\n offset: number;\n /** Number of bytes of actual data */\n numbytes: number;\n}\n\n/**\n * Parsed sparse header information\n */\nexport interface SparseInfo {\n /** The actual (reconstructed) file size */\n realSize: number;\n /** Sparse map entries */\n entries: SparseEntry[];\n /** Whether there are more entries in extended headers */\n isExtended: boolean;\n}\n\n/**\n * Parse sparse entries from a buffer starting at given offset\n *\n * @param buf - Buffer containing sparse entries\n * @param startOffset - Offset in buffer where entries begin\n * @param maxEntries - Maximum number of entries to read\n * @returns Array of valid sparse entries (stops at first zero entry)\n */\nfunction parseSparseEntries(buf: Buffer, startOffset: number, maxEntries: number): SparseEntry[] {\n const entries: SparseEntry[] = [];\n\n for (let i = 0; i < maxEntries; i++) {\n const entryOffset = startOffset + i * SPARSE_ENTRY_SIZE;\n const offset = decodeOct(buf, entryOffset, SPARSE_ENTRY_OFFSET_SIZE);\n const numbytes = decodeOct(buf, entryOffset + SPARSE_ENTRY_OFFSET_SIZE, SPARSE_ENTRY_NUMBYTES_SIZE);\n\n // Stop at first zero entry (end of sparse map)\n if (offset === 0 && numbytes === 0) {\n break;\n }\n\n entries.push({ offset, numbytes });\n }\n\n return entries;\n}\n\n/**\n * Parse GNU sparse header information from a tar header block\n *\n * @param headerBuf - The 512-byte tar header buffer\n * @returns Sparse info including real size, entries, and extended flag\n */\nexport function parseGnuSparseHeader(headerBuf: Buffer): SparseInfo {\n // Parse sparse entries from header (up to 4)\n const entries = parseSparseEntries(headerBuf, SPARSE_OFFSET, SPARSE_ENTRIES_IN_HEADER);\n\n // Parse isextended flag\n const isExtended = headerBuf[SPARSE_ISEXTENDED_OFFSET] !== 0;\n\n // Parse real file size\n const realSize = decodeOct(headerBuf, SPARSE_REALSIZE_OFFSET, SPARSE_REALSIZE_SIZE);\n\n return { realSize, entries, isExtended };\n}\n\n/**\n * Parse GNU sparse extended header block\n *\n * @param extBuf - The 512-byte extended sparse header buffer\n * @returns Object with entries and whether more extended blocks follow\n */\nexport function parseGnuSparseExtended(extBuf: Buffer): { entries: SparseEntry[]; isExtended: boolean } {\n // Parse sparse entries from extended block (up to 21)\n const entries = parseSparseEntries(extBuf, 0, SPARSE_EXTENDED_ENTRIES);\n\n // Parse isextended flag\n const isExtended = extBuf[SPARSE_EXTENDED_ISEXTENDED_OFFSET] !== 0;\n\n return { entries, isExtended };\n}\n\n/**\n * Calculate total data size from sparse map\n * This is the actual size of data stored in the archive (sum of all numbytes)\n */\nexport function sparseDataSize(entries: SparseEntry[]): number {\n let total = 0;\n for (let i = 0; i < entries.length; i++) {\n total += entries[i].numbytes;\n }\n return total;\n}\n\n/**\n * Stream that reconstructs a sparse file from data chunks\n *\n * Takes the sparse map and actual data, outputs reconstructed file\n * with zeros inserted for holes.\n *\n * Extends EntryStream to inherit pause/resume/pipe behavior.\n *\n * @internal\n */\nexport class SparseStream extends EntryStream {\n private entries: SparseEntry[];\n private realSize: number;\n private currentEntry: number;\n private virtualPosition: number;\n private entryBytesRemaining: number;\n\n constructor(entries: SparseEntry[], realSize: number) {\n super();\n this.entries = entries;\n this.realSize = realSize;\n this.currentEntry = 0;\n this.virtualPosition = 0;\n this.entryBytesRemaining = entries.length > 0 ? entries[0].numbytes : 0;\n }\n\n /**\n * Push data from the tar archive (actual sparse data chunk)\n * Overrides EntryStream.push() to reconstruct sparse file with holes.\n */\n push(data: Buffer): void {\n if (this.ended) return;\n\n let dataOffset = 0;\n\n while (dataOffset < data.length && this.currentEntry < this.entries.length) {\n const entry = this.entries[this.currentEntry];\n\n // First, emit zeros for any hole before current entry\n if (this.virtualPosition < entry.offset) {\n const holeSize = entry.offset - this.virtualPosition;\n this._emitZeros(holeSize);\n this.virtualPosition = entry.offset;\n }\n\n // Now emit actual data for this entry\n const toEmit = Math.min(this.entryBytesRemaining, data.length - dataOffset);\n if (toEmit > 0) {\n const chunk = data.slice(dataOffset, dataOffset + toEmit);\n super.push(chunk);\n dataOffset += toEmit;\n this.virtualPosition += toEmit;\n this.entryBytesRemaining -= toEmit;\n }\n\n // Move to next entry if current is exhausted\n if (this.entryBytesRemaining <= 0) {\n this.currentEntry++;\n if (this.currentEntry < this.entries.length) {\n this.entryBytesRemaining = this.entries[this.currentEntry].numbytes;\n }\n }\n }\n }\n\n /**\n * End the stream - emit any trailing zeros\n * Overrides EntryStream.end() to emit trailing zeros first.\n */\n end(): void {\n if (this.ended) return;\n\n // Emit remaining zeros to reach real file size\n if (this.virtualPosition < this.realSize) {\n this._emitZeros(this.realSize - this.virtualPosition);\n this.virtualPosition = this.realSize;\n }\n\n super.end();\n }\n\n /**\n * Emit zeros for a hole, reusing the shared zero buffer\n */\n private _emitZeros(size: number): void {\n const zeros = getZeroBuffer();\n let remaining = size;\n\n while (remaining > 0) {\n const toEmit = Math.min(remaining, ZERO_BUFFER_SIZE);\n // Slice from the reusable buffer to emit exact size needed\n super.push(zeros.slice(0, toEmit));\n remaining -= toEmit;\n }\n }\n}\n"],"names":["SparseStream","parseGnuSparseExtended","parseGnuSparseHeader","sparseDataSize","ZERO_BUFFER_SIZE","zeroBuffer","getZeroBuffer","Buffer","i","parseSparseEntries","buf","startOffset","maxEntries","entries","entryOffset","SPARSE_ENTRY_SIZE","offset","decodeOct","SPARSE_ENTRY_OFFSET_SIZE","numbytes","SPARSE_ENTRY_NUMBYTES_SIZE","push","headerBuf","SPARSE_OFFSET","SPARSE_ENTRIES_IN_HEADER","isExtended","SPARSE_ISEXTENDED_OFFSET","realSize","SPARSE_REALSIZE_OFFSET","SPARSE_REALSIZE_SIZE","extBuf","SPARSE_EXTENDED_ENTRIES","SPARSE_EXTENDED_ISEXTENDED_OFFSET","total","length","currentEntry","virtualPosition","entryBytesRemaining","data","ended","dataOffset","entry","holeSize","_emitZeros","toEmit","Math","min","chunk","slice","end","size","zeros","remaining","EntryStream"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;;;;;;;;;;;QA8HYA;eAAAA;;QAhCGC;eAAAA;;QAnBAC;eAAAA;;QAiCAC;eAAAA;;;2BA1GqP;oEAC7O;yBACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,uDAAuD;AACvD,IAAMC,mBAAmB;AACzB,IAAIC,aAA4B;AAEhC,SAASC;IACP,IAAI,CAACD,YAAY;QACfA,aAAa,IAAIE,OAAOH;QACxB,IAAK,IAAII,IAAI,GAAGA,IAAIJ,kBAAkBI,IAAK;YACzCH,UAAU,CAACG,EAAE,GAAG;QAClB;IACF;IACA,OAAOH;AACT;AAwBA;;;;;;;CAOC,GACD,SAASI,mBAAmBC,GAAW,EAAEC,WAAmB,EAAEC,UAAkB;IAC9E,IAAMC,UAAyB,EAAE;IAEjC,IAAK,IAAIL,IAAI,GAAGA,IAAII,YAAYJ,IAAK;QACnC,IAAMM,cAAcH,cAAcH,IAAIO,8BAAiB;QACvD,IAAMC,SAASC,IAAAA,oBAAS,EAACP,KAAKI,aAAaI,qCAAwB;QACnE,IAAMC,WAAWF,IAAAA,oBAAS,EAACP,KAAKI,cAAcI,qCAAwB,EAAEE,uCAA0B;QAElG,+CAA+C;QAC/C,IAAIJ,WAAW,KAAKG,aAAa,GAAG;YAClC;QACF;QAEAN,QAAQQ,IAAI,CAAC;YAAEL,QAAAA;YAAQG,UAAAA;QAAS;IAClC;IAEA,OAAON;AACT;AAQO,SAASX,qBAAqBoB,SAAiB;IACpD,6CAA6C;IAC7C,IAAMT,UAAUJ,mBAAmBa,WAAWC,0BAAa,EAAEC,qCAAwB;IAErF,wBAAwB;IACxB,IAAMC,aAAaH,SAAS,CAACI,qCAAwB,CAAC,KAAK;IAE3D,uBAAuB;IACvB,IAAMC,WAAWV,IAAAA,oBAAS,EAACK,WAAWM,mCAAsB,EAAEC,iCAAoB;IAElF,OAAO;QAAEF,UAAAA;QAAUd,SAAAA;QAASY,YAAAA;IAAW;AACzC;AAQO,SAASxB,uBAAuB6B,MAAc;IACnD,sDAAsD;IACtD,IAAMjB,UAAUJ,mBAAmBqB,QAAQ,GAAGC,oCAAuB;IAErE,wBAAwB;IACxB,IAAMN,aAAaK,MAAM,CAACE,8CAAiC,CAAC,KAAK;IAEjE,OAAO;QAAEnB,SAAAA;QAASY,YAAAA;IAAW;AAC/B;AAMO,SAAStB,eAAeU,OAAsB;IACnD,IAAIoB,QAAQ;IACZ,IAAK,IAAIzB,IAAI,GAAGA,IAAIK,QAAQqB,MAAM,EAAE1B,IAAK;QACvCyB,SAASpB,OAAO,CAACL,EAAE,CAACW,QAAQ;IAC9B;IACA,OAAOc;AACT;AAYO,IAAA,AAAMjC,6BAAN;;cAAMA;aAAAA,aAOCa,OAAsB,EAAEc,QAAgB;gCAPzC3B;;gBAQT,kBARSA;QAST,MAAKa,OAAO,GAAGA;QACf,MAAKc,QAAQ,GAAGA;QAChB,MAAKQ,YAAY,GAAG;QACpB,MAAKC,eAAe,GAAG;QACvB,MAAKC,mBAAmB,GAAGxB,QAAQqB,MAAM,GAAG,IAAIrB,OAAO,CAAC,EAAE,CAACM,QAAQ,GAAG;;;iBAb7DnB;IAgBX;;;GAGC,GACDqB,OAAAA,IAiCC,GAjCDA,SAAAA,KAAKiB,IAAY;QACf,IAAI,IAAI,CAACC,KAAK,EAAE;QAEhB,IAAIC,aAAa;QAEjB,MAAOA,aAAaF,KAAKJ,MAAM,IAAI,IAAI,CAACC,YAAY,GAAG,IAAI,CAACtB,OAAO,CAACqB,MAAM,CAAE;YAC1E,IAAMO,QAAQ,IAAI,CAAC5B,OAAO,CAAC,IAAI,CAACsB,YAAY,CAAC;YAE7C,sDAAsD;YACtD,IAAI,IAAI,CAACC,eAAe,GAAGK,MAAMzB,MAAM,EAAE;gBACvC,IAAM0B,WAAWD,MAAMzB,MAAM,GAAG,IAAI,CAACoB,eAAe;gBACpD,IAAI,CAACO,UAAU,CAACD;gBAChB,IAAI,CAACN,eAAe,GAAGK,MAAMzB,MAAM;YACrC;YAEA,sCAAsC;YACtC,IAAM4B,SAASC,KAAKC,GAAG,CAAC,IAAI,CAACT,mBAAmB,EAAEC,KAAKJ,MAAM,GAAGM;YAChE,IAAII,SAAS,GAAG;gBACd,IAAMG,QAAQT,KAAKU,KAAK,CAACR,YAAYA,aAAaI;gBAClD,uBAvCK5C,yBAuCCqB,QAAN,IAAK,aAAM0B;gBACXP,cAAcI;gBACd,IAAI,CAACR,eAAe,IAAIQ;gBACxB,IAAI,CAACP,mBAAmB,IAAIO;YAC9B;YAEA,6CAA6C;YAC7C,IAAI,IAAI,CAACP,mBAAmB,IAAI,GAAG;gBACjC,IAAI,CAACF,YAAY;gBACjB,IAAI,IAAI,CAACA,YAAY,GAAG,IAAI,CAACtB,OAAO,CAACqB,MAAM,EAAE;oBAC3C,IAAI,CAACG,mBAAmB,GAAG,IAAI,CAACxB,OAAO,CAAC,IAAI,CAACsB,YAAY,CAAC,CAAChB,QAAQ;gBACrE;YACF;QACF;IACF;IAEA;;;GAGC,GACD8B,OAAAA,GAUC,GAVDA,SAAAA;QACE,IAAI,IAAI,CAACV,KAAK,EAAE;QAEhB,+CAA+C;QAC/C,IAAI,IAAI,CAACH,eAAe,GAAG,IAAI,CAACT,QAAQ,EAAE;YACxC,IAAI,CAACgB,UAAU,CAAC,IAAI,CAAChB,QAAQ,GAAG,IAAI,CAACS,eAAe;YACpD,IAAI,CAACA,eAAe,GAAG,IAAI,CAACT,QAAQ;QACtC;QAEA,uBApES3B,yBAoEHiD,OAAN,IAAK;IACP;IAEA;;GAEC,GACD,OAAQN,UAUP,GAVD,SAAQA,WAAWO,IAAY;QAC7B,IAAMC,QAAQ7C;QACd,IAAI8C,YAAYF;QAEhB,MAAOE,YAAY,EAAG;YACpB,IAAMR,SAASC,KAAKC,GAAG,CAACM,WAAWhD;YACnC,2DAA2D;YAC3D,uBAjFOJ,yBAiFDqB,QAAN,IAAK,aAAM8B,MAAMH,KAAK,CAAC,GAAGJ;YAC1BQ,aAAaR;QACf;IACF;WApFW5C;EAAqBqD,sBAAW"}
|
package/dist/esm/FileEntry.js
CHANGED
|
@@ -23,7 +23,7 @@ let TarFileEntry = class TarFileEntry extends FileEntry {
|
|
|
23
23
|
}
|
|
24
24
|
_writeFile(fullPath, _options, callback) {
|
|
25
25
|
if (!this.stream) {
|
|
26
|
-
callback(new Error('
|
|
26
|
+
callback(new Error('FileEntry missing stream. Check for calling create multiple times'));
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
const stream = this.stream;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/FileEntry.ts"],"sourcesContent":["import { type FileAttributes, FileEntry, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\n\nimport type Lock from './lib/Lock.ts';\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n }\n\n create(dest: string, options: ExtractOptions | NoParamCallback, callback: NoParamCallback): undefined | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n if (typeof callback === 'function') {\n options = options || {};\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n\n return new Promise((resolve, reject) => {\n this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): undefined {\n if (!this.stream) {\n callback(new Error('
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/FileEntry.ts"],"sourcesContent":["import { type FileAttributes, FileEntry, type NoParamCallback, waitForAccess } from 'extract-base-iterator';\nimport fs from 'fs';\nimport oo from 'on-one';\n\nimport type Lock from './lib/Lock.ts';\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarFileEntry extends FileEntry {\n private lock: Lock;\n private stream: NodeJS.ReadableStream;\n\n constructor(attributes: FileAttributes, stream: NodeJS.ReadableStream, lock: Lock) {\n super(attributes);\n this.stream = stream;\n this.lock = lock;\n this.lock.retain();\n }\n\n create(dest: string, options: ExtractOptions | NoParamCallback, callback: NoParamCallback): undefined | Promise<boolean> {\n if (typeof options === 'function') {\n callback = options;\n options = null;\n }\n if (typeof callback === 'function') {\n options = options || {};\n return FileEntry.prototype.create.call(this, dest, options, (err?: Error) => {\n callback(err);\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n });\n }\n\n return new Promise((resolve, reject) => {\n this.create(dest, options, (err?: Error, done?: boolean) => (err ? reject(err) : resolve(done)));\n });\n }\n\n _writeFile(fullPath: string, _options: ExtractOptions, callback: NoParamCallback): undefined {\n if (!this.stream) {\n callback(new Error('FileEntry missing stream. Check for calling create multiple times'));\n return;\n }\n\n const stream = this.stream;\n this.stream = null;\n try {\n const res = stream.pipe(fs.createWriteStream(fullPath));\n oo(res, ['error', 'end', 'close', 'finish'], (err?: Error) => {\n err ? callback(err) : waitForAccess(fullPath, callback); // gunzip stream returns prematurely occasionally\n });\n } catch (err) {\n callback(err);\n }\n }\n\n destroy() {\n FileEntry.prototype.destroy.call(this);\n if (this.stream) {\n this.stream.resume(); // drain stream\n this.stream = null;\n }\n if (this.lock) {\n this.lock.release();\n this.lock = null;\n }\n }\n}\n"],"names":["FileEntry","waitForAccess","fs","oo","TarFileEntry","create","dest","options","callback","prototype","call","err","lock","release","Promise","resolve","reject","done","_writeFile","fullPath","_options","stream","Error","res","pipe","createWriteStream","destroy","resume","attributes","retain"],"mappings":"AAAA,SAA8BA,SAAS,EAAwBC,aAAa,QAAQ,wBAAwB;AAC5G,OAAOC,QAAQ,KAAK;AACpB,OAAOC,QAAQ,SAAS;AAKT,IAAA,AAAMC,eAAN,MAAMA,qBAAqBJ;IAWxCK,OAAOC,IAAY,EAAEC,OAAyC,EAAEC,QAAyB,EAAgC;QACvH,IAAI,OAAOD,YAAY,YAAY;YACjCC,WAAWD;YACXA,UAAU;QACZ;QACA,IAAI,OAAOC,aAAa,YAAY;YAClCD,UAAUA,WAAW,CAAC;YACtB,OAAOP,UAAUS,SAAS,CAACJ,MAAM,CAACK,IAAI,CAAC,IAAI,EAAEJ,MAAMC,SAAS,CAACI;gBAC3DH,SAASG;gBACT,IAAI,IAAI,CAACC,IAAI,EAAE;oBACb,IAAI,CAACA,IAAI,CAACC,OAAO;oBACjB,IAAI,CAACD,IAAI,GAAG;gBACd;YACF;QACF;QAEA,OAAO,IAAIE,QAAQ,CAACC,SAASC;YAC3B,IAAI,CAACX,MAAM,CAACC,MAAMC,SAAS,CAACI,KAAaM,OAAoBN,MAAMK,OAAOL,OAAOI,QAAQE;QAC3F;IACF;IAEAC,WAAWC,QAAgB,EAAEC,QAAwB,EAAEZ,QAAyB,EAAa;QAC3F,IAAI,CAAC,IAAI,CAACa,MAAM,EAAE;YAChBb,SAAS,IAAIc,MAAM;YACnB;QACF;QAEA,MAAMD,SAAS,IAAI,CAACA,MAAM;QAC1B,IAAI,CAACA,MAAM,GAAG;QACd,IAAI;YACF,MAAME,MAAMF,OAAOG,IAAI,CAACtB,GAAGuB,iBAAiB,CAACN;YAC7ChB,GAAGoB,KAAK;gBAAC;gBAAS;gBAAO;gBAAS;aAAS,EAAE,CAACZ;gBAC5CA,MAAMH,SAASG,OAAOV,cAAckB,UAAUX,WAAW,iDAAiD;YAC5G;QACF,EAAE,OAAOG,KAAK;YACZH,SAASG;QACX;IACF;IAEAe,UAAU;QACR1B,UAAUS,SAAS,CAACiB,OAAO,CAAChB,IAAI,CAAC,IAAI;QACrC,IAAI,IAAI,CAACW,MAAM,EAAE;YACf,IAAI,CAACA,MAAM,CAACM,MAAM,IAAI,eAAe;YACrC,IAAI,CAACN,MAAM,GAAG;QAChB;QACA,IAAI,IAAI,CAACT,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACC,OAAO;YACjB,IAAI,CAACD,IAAI,GAAG;QACd;IACF;IAxDA,YAAYgB,UAA0B,EAAEP,MAA6B,EAAET,IAAU,CAAE;QACjF,KAAK,CAACgB;QACN,IAAI,CAACP,MAAM,GAAGA;QACd,IAAI,CAACT,IAAI,GAAGA;QACZ,IAAI,CAACA,IAAI,CAACiB,MAAM;IAClB;AAoDF;AA7DA,SAAqBzB,0BA6DpB"}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import BaseIterator from 'extract-base-iterator';
|
|
2
2
|
import Lock from './lib/Lock.js';
|
|
3
|
+
import TarExtract from './tar/TarExtract.js';
|
|
3
4
|
import type { ExtractOptions } from './types.js';
|
|
4
5
|
export default class TarIterator extends BaseIterator {
|
|
6
|
+
/** @internal @hidden */
|
|
5
7
|
lock: Lock;
|
|
6
|
-
|
|
8
|
+
/** @internal @hidden */
|
|
9
|
+
extract: TarExtract;
|
|
7
10
|
constructor(source: string | NodeJS.ReadableStream, options?: ExtractOptions);
|
|
8
11
|
end(err?: Error): void;
|
|
9
12
|
}
|
package/dist/esm/TarIterator.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import once from 'call-once-fn';
|
|
2
2
|
import BaseIterator from 'extract-base-iterator';
|
|
3
3
|
import fs from 'fs';
|
|
4
|
-
import * as tarStream from 'tar-stream-compat';
|
|
5
4
|
import Lock from './lib/Lock.js';
|
|
6
5
|
import nextEntry from './nextEntry.js';
|
|
6
|
+
import TarExtract from './tar/TarExtract.js';
|
|
7
7
|
let TarIterator = class TarIterator extends BaseIterator {
|
|
8
8
|
end(err) {
|
|
9
9
|
if (this.lock) {
|
|
@@ -24,7 +24,10 @@ let TarIterator = class TarIterator extends BaseIterator {
|
|
|
24
24
|
cancelled = true;
|
|
25
25
|
};
|
|
26
26
|
this.processing.push(setup);
|
|
27
|
-
|
|
27
|
+
// Use our pure TarExtract instead of tar-stream-compat
|
|
28
|
+
// Note: options passed here are ExtractOptions (strip, force, etc.)
|
|
29
|
+
// TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different
|
|
30
|
+
this.extract = new TarExtract();
|
|
28
31
|
const pipe = (cb)=>{
|
|
29
32
|
try {
|
|
30
33
|
if (typeof source === 'string') source = fs.createReadStream(source);
|
|
@@ -32,9 +35,22 @@ let TarIterator = class TarIterator extends BaseIterator {
|
|
|
32
35
|
cb(err);
|
|
33
36
|
}
|
|
34
37
|
const end = once(cb);
|
|
35
|
-
|
|
38
|
+
const self = this;
|
|
39
|
+
source.on('data', function onData(chunk) {
|
|
40
|
+
try {
|
|
41
|
+
if (self.extract) self.extract.write(chunk);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
// Handle synchronous errors from TarExtract (e.g., invalid format)
|
|
44
|
+
end(err);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
source.on('data', function onFirstData() {
|
|
48
|
+
end();
|
|
49
|
+
});
|
|
36
50
|
source.on('error', end);
|
|
37
|
-
source.
|
|
51
|
+
source.on('end', function onEnd() {
|
|
52
|
+
if (self.extract) self.extract.end();
|
|
53
|
+
});
|
|
38
54
|
};
|
|
39
55
|
pipe((err)=>{
|
|
40
56
|
this.processing.remove(setup);
|
|
@@ -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';\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/TarIterator.ts"],"sourcesContent":["import once from 'call-once-fn';\nimport BaseIterator from 'extract-base-iterator';\nimport fs from 'fs';\n\nimport Lock from './lib/Lock.ts';\nimport nextEntry from './nextEntry.ts';\nimport TarExtract from './tar/TarExtract.ts';\n\nimport type { ExtractOptions } from './types.ts';\n\nexport default class TarIterator extends BaseIterator {\n /** @internal @hidden */\n lock: Lock;\n /** @internal @hidden */\n extract: TarExtract;\n\n constructor(source: string | NodeJS.ReadableStream, options: ExtractOptions = {}) {\n super(options);\n this.lock = new Lock();\n this.lock.iterator = this;\n\n let cancelled = false;\n const setup = (): undefined => {\n cancelled = true;\n };\n this.processing.push(setup);\n\n // Use our pure TarExtract instead of tar-stream-compat\n // Note: options passed here are ExtractOptions (strip, force, etc.)\n // TarExtract uses TarExtractOptions (filenameEncoding, etc.) which is different\n this.extract = new TarExtract();\n\n const pipe = (cb) => {\n try {\n if (typeof source === 'string') source = fs.createReadStream(source);\n } catch (err) {\n cb(err);\n }\n\n const end = once(cb);\n const self = this;\n (source as NodeJS.ReadableStream).on('data', function onData(chunk) {\n try {\n if (self.extract) self.extract.write(chunk);\n } catch (err) {\n // Handle synchronous errors from TarExtract (e.g., invalid format)\n end(err);\n }\n });\n (source as NodeJS.ReadableStream).on('data', function onFirstData() {\n end();\n });\n (source as NodeJS.ReadableStream).on('error', end);\n (source as NodeJS.ReadableStream).on('end', function onEnd() {\n if (self.extract) self.extract.end();\n });\n };\n pipe((err) => {\n this.processing.remove(setup);\n if (this.done || cancelled) return; // done\n err ? this.end(err) : this.push(nextEntry.bind(null, null));\n });\n }\n\n end(err?: Error) {\n if (this.lock) {\n this.lock.err = err;\n this.lock.release();\n this.lock = null;\n } else {\n BaseIterator.prototype.end.call(this, err); // call in lock release so end is properly handled\n }\n this.extract = null;\n }\n}\n"],"names":["once","BaseIterator","fs","Lock","nextEntry","TarExtract","TarIterator","end","err","lock","release","prototype","call","extract","source","options","iterator","cancelled","setup","processing","push","pipe","cb","createReadStream","self","on","onData","chunk","write","onFirstData","onEnd","remove","done","bind"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,OAAOC,kBAAkB,wBAAwB;AACjD,OAAOC,QAAQ,KAAK;AAEpB,OAAOC,UAAU,gBAAgB;AACjC,OAAOC,eAAe,iBAAiB;AACvC,OAAOC,gBAAgB,sBAAsB;AAI9B,IAAA,AAAMC,cAAN,MAAMA,oBAAoBL;IAsDvCM,IAAIC,GAAW,EAAE;QACf,IAAI,IAAI,CAACC,IAAI,EAAE;YACb,IAAI,CAACA,IAAI,CAACD,GAAG,GAAGA;YAChB,IAAI,CAACC,IAAI,CAACC,OAAO;YACjB,IAAI,CAACD,IAAI,GAAG;QACd,OAAO;YACLR,aAAaU,SAAS,CAACJ,GAAG,CAACK,IAAI,CAAC,IAAI,EAAEJ,MAAM,kDAAkD;QAChG;QACA,IAAI,CAACK,OAAO,GAAG;IACjB;IAzDA,YAAYC,MAAsC,EAAEC,UAA0B,CAAC,CAAC,CAAE;QAChF,KAAK,CAACA;QACN,IAAI,CAACN,IAAI,GAAG,IAAIN;QAChB,IAAI,CAACM,IAAI,CAACO,QAAQ,GAAG,IAAI;QAEzB,IAAIC,YAAY;QAChB,MAAMC,QAAQ;YACZD,YAAY;QACd;QACA,IAAI,CAACE,UAAU,CAACC,IAAI,CAACF;QAErB,uDAAuD;QACvD,oEAAoE;QACpE,gFAAgF;QAChF,IAAI,CAACL,OAAO,GAAG,IAAIR;QAEnB,MAAMgB,OAAO,CAACC;YACZ,IAAI;gBACF,IAAI,OAAOR,WAAW,UAAUA,SAASZ,GAAGqB,gBAAgB,CAACT;YAC/D,EAAE,OAAON,KAAK;gBACZc,GAAGd;YACL;YAEA,MAAMD,MAAMP,KAAKsB;YACjB,MAAME,OAAO,IAAI;YAChBV,OAAiCW,EAAE,CAAC,QAAQ,SAASC,OAAOC,KAAK;gBAChE,IAAI;oBACF,IAAIH,KAAKX,OAAO,EAAEW,KAAKX,OAAO,CAACe,KAAK,CAACD;gBACvC,EAAE,OAAOnB,KAAK;oBACZ,mEAAmE;oBACnED,IAAIC;gBACN;YACF;YACCM,OAAiCW,EAAE,CAAC,QAAQ,SAASI;gBACpDtB;YACF;YACCO,OAAiCW,EAAE,CAAC,SAASlB;YAC7CO,OAAiCW,EAAE,CAAC,OAAO,SAASK;gBACnD,IAAIN,KAAKX,OAAO,EAAEW,KAAKX,OAAO,CAACN,GAAG;YACpC;QACF;QACAc,KAAK,CAACb;YACJ,IAAI,CAACW,UAAU,CAACY,MAAM,CAACb;YACvB,IAAI,IAAI,CAACc,IAAI,IAAIf,WAAW,QAAQ,OAAO;YAC3CT,MAAM,IAAI,CAACD,GAAG,CAACC,OAAO,IAAI,CAACY,IAAI,CAAChB,UAAU6B,IAAI,CAAC,MAAM;QACvD;IACF;AAYF;AAhEA,SAAqB3B,yBAgEpB"}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/index.ts"],"sourcesContent":["export { default } from './TarIterator.ts';\nexport * from './types.ts';\n"],"names":["default"],"mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,cAAc,aAAa"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/index.ts"],"sourcesContent":["export { default } from './TarIterator.ts';\nexport { type TarCodedError, TarErrorCode } from './tar/errors.ts';\nexport * from './types.ts';\n"],"names":["default","TarErrorCode"],"mappings":"AAAA,SAASA,OAAO,QAAQ,mBAAmB;AAC3C,SAA6BC,YAAY,QAAQ,kBAAkB;AACnE,cAAc,aAAa"}
|
package/dist/esm/nextEntry.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import once from 'call-once-fn';
|
|
2
2
|
import { DirectoryEntry, LinkEntry, SymbolicLinkEntry } from 'extract-base-iterator';
|
|
3
|
-
import compact from 'lodash.compact';
|
|
4
3
|
import path from 'path';
|
|
5
4
|
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
|
+
};
|
|
6
9
|
export default function nextEntry(next, iterator, callback) {
|
|
7
10
|
const extract = iterator.extract;
|
|
8
11
|
if (!extract) return callback(new Error('Extract missing'));
|
|
@@ -12,22 +15,28 @@ export default function nextEntry(next, iterator, callback) {
|
|
|
12
15
|
extract.removeListener('finish', onEnd);
|
|
13
16
|
// keep processing
|
|
14
17
|
if (entry) iterator.push(nextEntry.bind(null, next));
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
// Use setImmediate to defer the callback invocation
|
|
19
|
+
// This ensures proper async behavior with the BaseIterator
|
|
20
|
+
_setImmediate(()=>{
|
|
21
|
+
err ? callback(err) : callback(null, entry ? {
|
|
22
|
+
done: false,
|
|
23
|
+
value: entry
|
|
24
|
+
} : {
|
|
25
|
+
done: true,
|
|
26
|
+
value: null
|
|
27
|
+
});
|
|
21
28
|
});
|
|
22
29
|
});
|
|
23
30
|
const onError = callback;
|
|
24
31
|
const onEnd = callback.bind(null, null);
|
|
25
32
|
const onEntry = function onEntry(header, stream, next) {
|
|
26
|
-
if (iterator.isDone())
|
|
33
|
+
if (iterator.isDone()) {
|
|
34
|
+
return nextCallback(null, null, next);
|
|
35
|
+
}
|
|
27
36
|
const attributes = {
|
|
28
37
|
...header
|
|
29
38
|
};
|
|
30
|
-
attributes.path =
|
|
39
|
+
attributes.path = header.name.split(path.sep).filter(Boolean).join(path.sep);
|
|
31
40
|
attributes.mtime = new Date(attributes.mtime);
|
|
32
41
|
switch(attributes.type){
|
|
33
42
|
case 'directory':
|
|
@@ -50,5 +59,13 @@ export default function nextEntry(next, iterator, callback) {
|
|
|
50
59
|
extract.on('entry', onEntry);
|
|
51
60
|
extract.on('error', onError);
|
|
52
61
|
extract.on('finish', onEnd);
|
|
53
|
-
|
|
62
|
+
// Resume parsing to emit any pending entry
|
|
63
|
+
// For first call (next is null), this triggers the first entry emission
|
|
64
|
+
// For subsequent calls, next() unlocks the parser which then processes the next header
|
|
65
|
+
if (next) {
|
|
66
|
+
next();
|
|
67
|
+
} else {
|
|
68
|
+
// First call - resume to emit any pending entry
|
|
69
|
+
extract.resume();
|
|
70
|
+
}
|
|
54
71
|
}
|
|
@@ -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, SymbolicLinkEntry } from 'extract-base-iterator';\nimport path from 'path';\nimport FileEntry from './FileEntry.ts';\nimport type Iterator from './TarIterator.ts';\n\nimport type { Entry, EntryCallback } from './types.ts';\n\n// Node 0.8 compatible setImmediate (setImmediate was added in Node 0.10)\nconst _setImmediate =\n typeof setImmediate === 'function'\n ? setImmediate\n : typeof process !== 'undefined' && typeof process.nextTick === 'function'\n ? process.nextTick\n : function setImmediateFallback(fn: () => void) {\n setTimeout(fn, 0);\n };\n\nexport type TarNext = () => undefined;\nexport type NextCallback = (error?: Error, entry?: Entry, next?: TarNext) => undefined;\n\nexport default function nextEntry(next: TarNext, iterator: Iterator, callback: EntryCallback): undefined {\n const extract = iterator.extract;\n if (!extract) return callback(new Error('Extract missing'));\n\n const nextCallback = once((err?: Error, entry?: Entry, next?: TarNext) => {\n extract.removeListener('entry', onEntry);\n extract.removeListener('error', onError);\n extract.removeListener('finish', onEnd);\n\n // keep processing\n if (entry) iterator.push(nextEntry.bind(null, next));\n\n // Use setImmediate to defer the callback invocation\n // This ensures proper async behavior with the BaseIterator\n _setImmediate(() => {\n err ? callback(err) : callback(null, entry ? { done: false, value: entry } : { done: true, value: null });\n });\n }) as NextCallback;\n\n const onError = callback;\n const onEnd = callback.bind(null, null);\n const onEntry = function onEntry(header, stream, next: TarNext) {\n if (iterator.isDone()) {\n return nextCallback(null, null, next);\n }\n\n const attributes = { ...header };\n attributes.path = header.name.split(path.sep).filter(Boolean).join(path.sep);\n attributes.mtime = new Date(attributes.mtime);\n\n switch (attributes.type) {\n case 'directory':\n stream.resume(); // drain stream\n return nextCallback(null, new DirectoryEntry(attributes), next);\n case 'symlink':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new SymbolicLinkEntry(attributes), next);\n case 'link':\n stream.resume(); // drain stream\n attributes.linkpath = header.linkname;\n return nextCallback(null, new LinkEntry(attributes), next);\n case 'file':\n return nextCallback(null, new FileEntry(attributes, stream, iterator.lock), next);\n }\n\n stream.resume(); // drain stream\n return nextCallback(new Error(`Unrecognized entry type: ${attributes.type}`), null, next);\n };\n\n extract.on('entry', onEntry);\n extract.on('error', onError);\n extract.on('finish', onEnd);\n\n // Resume parsing to emit any pending entry\n // For first call (next is null), this triggers the first entry emission\n // For subsequent calls, next() unlocks the parser which then processes the next header\n if (next) {\n next();\n } else {\n // First call - resume to emit any pending entry\n extract.resume();\n }\n}\n"],"names":["once","DirectoryEntry","LinkEntry","SymbolicLinkEntry","path","FileEntry","_setImmediate","setImmediate","process","nextTick","setImmediateFallback","fn","setTimeout","nextEntry","next","iterator","callback","extract","Error","nextCallback","err","entry","removeListener","onEntry","onError","onEnd","push","bind","done","value","header","stream","isDone","attributes","name","split","sep","filter","Boolean","join","mtime","Date","type","resume","linkpath","linkname","lock","on"],"mappings":"AAAA,OAAOA,UAAU,eAAe;AAChC,SAASC,cAAc,EAAEC,SAAS,EAAEC,iBAAiB,QAAQ,wBAAwB;AACrF,OAAOC,UAAU,OAAO;AACxB,OAAOC,eAAe,iBAAiB;AAKvC,yEAAyE;AACzE,MAAMC,gBACJ,OAAOC,iBAAiB,aACpBA,eACA,OAAOC,YAAY,eAAe,OAAOA,QAAQC,QAAQ,KAAK,aAC5DD,QAAQC,QAAQ,GAChB,SAASC,qBAAqBC,EAAc;IAC1CC,WAAWD,IAAI;AACjB;AAKR,eAAe,SAASE,UAAUC,IAAa,EAAEC,QAAkB,EAAEC,QAAuB;IAC1F,MAAMC,UAAUF,SAASE,OAAO;IAChC,IAAI,CAACA,SAAS,OAAOD,SAAS,IAAIE,MAAM;IAExC,MAAMC,eAAenB,KAAK,CAACoB,KAAaC,OAAeP;QACrDG,QAAQK,cAAc,CAAC,SAASC;QAChCN,QAAQK,cAAc,CAAC,SAASE;QAChCP,QAAQK,cAAc,CAAC,UAAUG;QAEjC,kBAAkB;QAClB,IAAIJ,OAAON,SAASW,IAAI,CAACb,UAAUc,IAAI,CAAC,MAAMb;QAE9C,oDAAoD;QACpD,2DAA2D;QAC3DR,cAAc;YACZc,MAAMJ,SAASI,OAAOJ,SAAS,MAAMK,QAAQ;gBAAEO,MAAM;gBAAOC,OAAOR;YAAM,IAAI;gBAAEO,MAAM;gBAAMC,OAAO;YAAK;QACzG;IACF;IAEA,MAAML,UAAUR;IAChB,MAAMS,QAAQT,SAASW,IAAI,CAAC,MAAM;IAClC,MAAMJ,UAAU,SAASA,QAAQO,MAAM,EAAEC,MAAM,EAAEjB,IAAa;QAC5D,IAAIC,SAASiB,MAAM,IAAI;YACrB,OAAOb,aAAa,MAAM,MAAML;QAClC;QAEA,MAAMmB,aAAa;YAAE,GAAGH,MAAM;QAAC;QAC/BG,WAAW7B,IAAI,GAAG0B,OAAOI,IAAI,CAACC,KAAK,CAAC/B,KAAKgC,GAAG,EAAEC,MAAM,CAACC,SAASC,IAAI,CAACnC,KAAKgC,GAAG;QAC3EH,WAAWO,KAAK,GAAG,IAAIC,KAAKR,WAAWO,KAAK;QAE5C,OAAQP,WAAWS,IAAI;YACrB,KAAK;gBACHX,OAAOY,MAAM,IAAI,eAAe;gBAChC,OAAOxB,aAAa,MAAM,IAAIlB,eAAegC,aAAanB;YAC5D,KAAK;gBACHiB,OAAOY,MAAM,IAAI,eAAe;gBAChCV,WAAWW,QAAQ,GAAGd,OAAOe,QAAQ;gBACrC,OAAO1B,aAAa,MAAM,IAAIhB,kBAAkB8B,aAAanB;YAC/D,KAAK;gBACHiB,OAAOY,MAAM,IAAI,eAAe;gBAChCV,WAAWW,QAAQ,GAAGd,OAAOe,QAAQ;gBACrC,OAAO1B,aAAa,MAAM,IAAIjB,UAAU+B,aAAanB;YACvD,KAAK;gBACH,OAAOK,aAAa,MAAM,IAAId,UAAU4B,YAAYF,QAAQhB,SAAS+B,IAAI,GAAGhC;QAChF;QAEAiB,OAAOY,MAAM,IAAI,eAAe;QAChC,OAAOxB,aAAa,IAAID,MAAM,CAAC,yBAAyB,EAAEe,WAAWS,IAAI,EAAE,GAAG,MAAM5B;IACtF;IAEAG,QAAQ8B,EAAE,CAAC,SAASxB;IACpBN,QAAQ8B,EAAE,CAAC,SAASvB;IACpBP,QAAQ8B,EAAE,CAAC,UAAUtB;IAErB,2CAA2C;IAC3C,wEAAwE;IACxE,uFAAuF;IACvF,IAAIX,MAAM;QACRA;IACF,OAAO;QACL,gDAAgD;QAChDG,QAAQ0B,MAAM;IAChB;AACF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BufferList - Simple linked list for buffering streaming data
|
|
3
|
+
*
|
|
4
|
+
* Node 0.8 compatible - uses only basic Buffer APIs:
|
|
5
|
+
* - new Buffer(size)
|
|
6
|
+
* - Buffer.copy(target, targetStart, sourceStart, sourceEnd)
|
|
7
|
+
* - Buffer.slice(start, end)
|
|
8
|
+
* - Buffer.length
|
|
9
|
+
*/
|
|
10
|
+
export default class BufferList {
|
|
11
|
+
private head;
|
|
12
|
+
private tail;
|
|
13
|
+
length: number;
|
|
14
|
+
/**
|
|
15
|
+
* Append a buffer to the end of the list
|
|
16
|
+
*/
|
|
17
|
+
append(buf: Buffer): void;
|
|
18
|
+
/**
|
|
19
|
+
* Consume and return n bytes from the front
|
|
20
|
+
* Returns a new buffer containing the consumed bytes
|
|
21
|
+
*/
|
|
22
|
+
consume(n: number): Buffer;
|
|
23
|
+
/**
|
|
24
|
+
* Clear all buffered data
|
|
25
|
+
*/
|
|
26
|
+
clear(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Check if buffer has at least n bytes available
|
|
29
|
+
*/
|
|
30
|
+
has(n: number): boolean;
|
|
31
|
+
}
|