tar-iterator 2.2.8 → 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.d.cts +11 -0
- package/dist/cjs/FileEntry.js +1 -1
- package/dist/cjs/FileEntry.js.map +1 -1
- package/dist/cjs/TarIterator.d.cts +12 -0
- 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 +3 -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/lib/Lock.d.cts +9 -0
- package/dist/cjs/nextEntry.d.cts +5 -0
- 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/cjs/types.d.cts +5 -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 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/iterators/tar-iterator/src/tar/index.ts"],"sourcesContent":["/**\n * Pure TAR Parser Module\n *\n * Node 0.8+ compatible TAR extraction without external dependencies.\n */\n\nexport { default as BufferList } from './BufferList.ts';\nexport * from './constants.ts';\nexport * from './headers.ts';\nexport { default as TarExtract, type TarExtractOptions } from './TarExtract.ts';\n"],"names":["default","BufferList","TarExtract"],"mappings":"AAAA;;;;CAIC,GAED,SAASA,WAAWC,UAAU,QAAQ,kBAAkB;AACxD,cAAc,iBAAiB;AAC/B,cAAc,eAAe;AAC7B,SAASD,WAAWE,UAAU,QAAgC,kBAAkB"}
|
|
@@ -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,172 @@
|
|
|
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
|
+
*/ import { 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.js';
|
|
17
|
+
import EntryStream from './EntryStream.js';
|
|
18
|
+
import { decodeOct } from './headers.js';
|
|
19
|
+
// Reusable zero buffer for sparse hole emission (64KB)
|
|
20
|
+
const ZERO_BUFFER_SIZE = 65536;
|
|
21
|
+
let zeroBuffer = null;
|
|
22
|
+
function getZeroBuffer() {
|
|
23
|
+
if (!zeroBuffer) {
|
|
24
|
+
zeroBuffer = new Buffer(ZERO_BUFFER_SIZE);
|
|
25
|
+
for(let i = 0; i < ZERO_BUFFER_SIZE; i++){
|
|
26
|
+
zeroBuffer[i] = 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return zeroBuffer;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parse sparse entries from a buffer starting at given offset
|
|
33
|
+
*
|
|
34
|
+
* @param buf - Buffer containing sparse entries
|
|
35
|
+
* @param startOffset - Offset in buffer where entries begin
|
|
36
|
+
* @param maxEntries - Maximum number of entries to read
|
|
37
|
+
* @returns Array of valid sparse entries (stops at first zero entry)
|
|
38
|
+
*/ function parseSparseEntries(buf, startOffset, maxEntries) {
|
|
39
|
+
const entries = [];
|
|
40
|
+
for(let i = 0; i < maxEntries; i++){
|
|
41
|
+
const entryOffset = startOffset + i * SPARSE_ENTRY_SIZE;
|
|
42
|
+
const offset = decodeOct(buf, entryOffset, SPARSE_ENTRY_OFFSET_SIZE);
|
|
43
|
+
const numbytes = decodeOct(buf, entryOffset + SPARSE_ENTRY_OFFSET_SIZE, SPARSE_ENTRY_NUMBYTES_SIZE);
|
|
44
|
+
// Stop at first zero entry (end of sparse map)
|
|
45
|
+
if (offset === 0 && numbytes === 0) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
entries.push({
|
|
49
|
+
offset,
|
|
50
|
+
numbytes
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return entries;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parse GNU sparse header information from a tar header block
|
|
57
|
+
*
|
|
58
|
+
* @param headerBuf - The 512-byte tar header buffer
|
|
59
|
+
* @returns Sparse info including real size, entries, and extended flag
|
|
60
|
+
*/ export function parseGnuSparseHeader(headerBuf) {
|
|
61
|
+
// Parse sparse entries from header (up to 4)
|
|
62
|
+
const entries = parseSparseEntries(headerBuf, SPARSE_OFFSET, SPARSE_ENTRIES_IN_HEADER);
|
|
63
|
+
// Parse isextended flag
|
|
64
|
+
const isExtended = headerBuf[SPARSE_ISEXTENDED_OFFSET] !== 0;
|
|
65
|
+
// Parse real file size
|
|
66
|
+
const realSize = decodeOct(headerBuf, SPARSE_REALSIZE_OFFSET, SPARSE_REALSIZE_SIZE);
|
|
67
|
+
return {
|
|
68
|
+
realSize,
|
|
69
|
+
entries,
|
|
70
|
+
isExtended
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Parse GNU sparse extended header block
|
|
75
|
+
*
|
|
76
|
+
* @param extBuf - The 512-byte extended sparse header buffer
|
|
77
|
+
* @returns Object with entries and whether more extended blocks follow
|
|
78
|
+
*/ export function parseGnuSparseExtended(extBuf) {
|
|
79
|
+
// Parse sparse entries from extended block (up to 21)
|
|
80
|
+
const entries = parseSparseEntries(extBuf, 0, SPARSE_EXTENDED_ENTRIES);
|
|
81
|
+
// Parse isextended flag
|
|
82
|
+
const isExtended = extBuf[SPARSE_EXTENDED_ISEXTENDED_OFFSET] !== 0;
|
|
83
|
+
return {
|
|
84
|
+
entries,
|
|
85
|
+
isExtended
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Calculate total data size from sparse map
|
|
90
|
+
* This is the actual size of data stored in the archive (sum of all numbytes)
|
|
91
|
+
*/ export function sparseDataSize(entries) {
|
|
92
|
+
let total = 0;
|
|
93
|
+
for(let i = 0; i < entries.length; i++){
|
|
94
|
+
total += entries[i].numbytes;
|
|
95
|
+
}
|
|
96
|
+
return total;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Stream that reconstructs a sparse file from data chunks
|
|
100
|
+
*
|
|
101
|
+
* Takes the sparse map and actual data, outputs reconstructed file
|
|
102
|
+
* with zeros inserted for holes.
|
|
103
|
+
*
|
|
104
|
+
* Extends EntryStream to inherit pause/resume/pipe behavior.
|
|
105
|
+
*
|
|
106
|
+
* @internal
|
|
107
|
+
*/ export class SparseStream extends EntryStream {
|
|
108
|
+
/**
|
|
109
|
+
* Push data from the tar archive (actual sparse data chunk)
|
|
110
|
+
* Overrides EntryStream.push() to reconstruct sparse file with holes.
|
|
111
|
+
*/ push(data) {
|
|
112
|
+
if (this.ended) return;
|
|
113
|
+
let dataOffset = 0;
|
|
114
|
+
while(dataOffset < data.length && this.currentEntry < this.entries.length){
|
|
115
|
+
const entry = this.entries[this.currentEntry];
|
|
116
|
+
// First, emit zeros for any hole before current entry
|
|
117
|
+
if (this.virtualPosition < entry.offset) {
|
|
118
|
+
const holeSize = entry.offset - this.virtualPosition;
|
|
119
|
+
this._emitZeros(holeSize);
|
|
120
|
+
this.virtualPosition = entry.offset;
|
|
121
|
+
}
|
|
122
|
+
// Now emit actual data for this entry
|
|
123
|
+
const toEmit = Math.min(this.entryBytesRemaining, data.length - dataOffset);
|
|
124
|
+
if (toEmit > 0) {
|
|
125
|
+
const chunk = data.slice(dataOffset, dataOffset + toEmit);
|
|
126
|
+
super.push(chunk);
|
|
127
|
+
dataOffset += toEmit;
|
|
128
|
+
this.virtualPosition += toEmit;
|
|
129
|
+
this.entryBytesRemaining -= toEmit;
|
|
130
|
+
}
|
|
131
|
+
// Move to next entry if current is exhausted
|
|
132
|
+
if (this.entryBytesRemaining <= 0) {
|
|
133
|
+
this.currentEntry++;
|
|
134
|
+
if (this.currentEntry < this.entries.length) {
|
|
135
|
+
this.entryBytesRemaining = this.entries[this.currentEntry].numbytes;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* End the stream - emit any trailing zeros
|
|
142
|
+
* Overrides EntryStream.end() to emit trailing zeros first.
|
|
143
|
+
*/ end() {
|
|
144
|
+
if (this.ended) return;
|
|
145
|
+
// Emit remaining zeros to reach real file size
|
|
146
|
+
if (this.virtualPosition < this.realSize) {
|
|
147
|
+
this._emitZeros(this.realSize - this.virtualPosition);
|
|
148
|
+
this.virtualPosition = this.realSize;
|
|
149
|
+
}
|
|
150
|
+
super.end();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Emit zeros for a hole, reusing the shared zero buffer
|
|
154
|
+
*/ _emitZeros(size) {
|
|
155
|
+
const zeros = getZeroBuffer();
|
|
156
|
+
let remaining = size;
|
|
157
|
+
while(remaining > 0){
|
|
158
|
+
const toEmit = Math.min(remaining, ZERO_BUFFER_SIZE);
|
|
159
|
+
// Slice from the reusable buffer to emit exact size needed
|
|
160
|
+
super.push(zeros.slice(0, toEmit));
|
|
161
|
+
remaining -= toEmit;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
constructor(entries, realSize){
|
|
165
|
+
super();
|
|
166
|
+
this.entries = entries;
|
|
167
|
+
this.realSize = realSize;
|
|
168
|
+
this.currentEntry = 0;
|
|
169
|
+
this.virtualPosition = 0;
|
|
170
|
+
this.entryBytesRemaining = entries.length > 0 ? entries[0].numbytes : 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -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":["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","EntryStream","decodeOct","ZERO_BUFFER_SIZE","zeroBuffer","getZeroBuffer","Buffer","i","parseSparseEntries","buf","startOffset","maxEntries","entries","entryOffset","offset","numbytes","push","parseGnuSparseHeader","headerBuf","isExtended","realSize","parseGnuSparseExtended","extBuf","sparseDataSize","total","length","SparseStream","data","ended","dataOffset","currentEntry","entry","virtualPosition","holeSize","_emitZeros","toEmit","Math","min","entryBytesRemaining","chunk","slice","end","size","zeros","remaining"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,wBAAwB,EAAEC,0BAA0B,EAAEC,wBAAwB,EAAEC,iBAAiB,EAAEC,uBAAuB,EAAEC,iCAAiC,EAAEC,wBAAwB,EAAEC,aAAa,EAAEC,sBAAsB,EAAEC,oBAAoB,QAAQ,iBAAiB;AACtR,OAAOC,iBAAiB,mBAAmB;AAC3C,SAASC,SAAS,QAAQ,eAAe;AAEzC,uDAAuD;AACvD,MAAMC,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,MAAMC,UAAyB,EAAE;IAEjC,IAAK,IAAIL,IAAI,GAAGA,IAAII,YAAYJ,IAAK;QACnC,MAAMM,cAAcH,cAAcH,IAAIb;QACtC,MAAMoB,SAASZ,UAAUO,KAAKI,aAAapB;QAC3C,MAAMsB,WAAWb,UAAUO,KAAKI,cAAcp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D,KAAK,CAACa,KAAK2B,MAAMH,KAAK,CAAC,GAAGL;YAC1BS,aAAaT;QACf;IACF;IA7EA,YAAYvB,OAAsB,EAAEQ,QAAgB,CAAE;QACpD,KAAK;QACL,IAAI,CAACR,OAAO,GAAGA;QACf,IAAI,CAACQ,QAAQ,GAAGA;QAChB,IAAI,CAACU,YAAY,GAAG;QACpB,IAAI,CAACE,eAAe,GAAG;QACvB,IAAI,CAACM,mBAAmB,GAAG1B,QAAQa,MAAM,GAAG,IAAIb,OAAO,CAAC,EAAE,CAACG,QAAQ,GAAG;IACxE;AAuEF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tar-iterator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Extract contents from tar archive type using an iterator API using streams or paths. Use stream interface and pipe transforms to add decompression algorithms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"extract",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsds build",
|
|
56
56
|
"format": "biome check --write --unsafe",
|
|
57
|
+
"prepublishOnly": "tsds validate",
|
|
57
58
|
"test": "mocha --no-timeouts test/**/*.test.*",
|
|
58
59
|
"test:engines": "nvu engines tsds test:node --no-timeouts",
|
|
59
60
|
"version": "tsds version"
|
|
@@ -61,20 +62,18 @@
|
|
|
61
62
|
"dependencies": {
|
|
62
63
|
"call-once-fn": "*",
|
|
63
64
|
"extract-base-iterator": "*",
|
|
64
|
-
"
|
|
65
|
-
"mkdirp-classic": "*",
|
|
66
|
-
"on-one": "*",
|
|
67
|
-
"rimraf2": "*",
|
|
68
|
-
"tar-stream-compat": "*"
|
|
65
|
+
"on-one": "*"
|
|
69
66
|
},
|
|
70
67
|
"devDependencies": {
|
|
71
|
-
"@types/mocha": "
|
|
72
|
-
"@types/node": "
|
|
68
|
+
"@types/mocha": "^10.0.10",
|
|
69
|
+
"@types/node": "^24.10.1",
|
|
73
70
|
"cr": "*",
|
|
74
71
|
"fs-iterator": "*",
|
|
75
72
|
"fs-stats-spys": "*",
|
|
73
|
+
"mkdirp-classic": "*",
|
|
76
74
|
"pinkie-promise": "*",
|
|
77
75
|
"queue-cb": "*",
|
|
76
|
+
"rimraf2": "*",
|
|
78
77
|
"unbzip2-stream": "*"
|
|
79
78
|
},
|
|
80
79
|
"engines": {
|