tar-xz 0.1.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.
Files changed (63) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +201 -0
  3. package/lib/browser/create.d.ts +27 -0
  4. package/lib/browser/create.d.ts.map +1 -0
  5. package/lib/browser/create.js +113 -0
  6. package/lib/browser/create.js.map +1 -0
  7. package/lib/browser/extract.d.ts +24 -0
  8. package/lib/browser/extract.d.ts.map +1 -0
  9. package/lib/browser/extract.js +112 -0
  10. package/lib/browser/extract.js.map +1 -0
  11. package/lib/browser/index.d.ts +7 -0
  12. package/lib/browser/index.d.ts.map +1 -0
  13. package/lib/browser/index.js +7 -0
  14. package/lib/browser/index.js.map +1 -0
  15. package/lib/browser/list.d.ts +23 -0
  16. package/lib/browser/list.d.ts.map +1 -0
  17. package/lib/browser/list.js +81 -0
  18. package/lib/browser/list.js.map +1 -0
  19. package/lib/index.browser.d.ts +12 -0
  20. package/lib/index.browser.d.ts.map +1 -0
  21. package/lib/index.browser.js +14 -0
  22. package/lib/index.browser.js.map +1 -0
  23. package/lib/index.d.ts +12 -0
  24. package/lib/index.d.ts.map +1 -0
  25. package/lib/index.js +14 -0
  26. package/lib/index.js.map +1 -0
  27. package/lib/node/create.d.ts +22 -0
  28. package/lib/node/create.d.ts.map +1 -0
  29. package/lib/node/create.js +155 -0
  30. package/lib/node/create.js.map +1 -0
  31. package/lib/node/extract.d.ts +30 -0
  32. package/lib/node/extract.d.ts.map +1 -0
  33. package/lib/node/extract.js +274 -0
  34. package/lib/node/extract.js.map +1 -0
  35. package/lib/node/index.d.ts +7 -0
  36. package/lib/node/index.d.ts.map +1 -0
  37. package/lib/node/index.js +7 -0
  38. package/lib/node/index.js.map +1 -0
  39. package/lib/node/list.d.ts +20 -0
  40. package/lib/node/list.d.ts.map +1 -0
  41. package/lib/node/list.js +115 -0
  42. package/lib/node/list.js.map +1 -0
  43. package/lib/tar/checksum.d.ts +40 -0
  44. package/lib/tar/checksum.d.ts.map +1 -0
  45. package/lib/tar/checksum.js +91 -0
  46. package/lib/tar/checksum.js.map +1 -0
  47. package/lib/tar/format.d.ts +87 -0
  48. package/lib/tar/format.d.ts.map +1 -0
  49. package/lib/tar/format.js +244 -0
  50. package/lib/tar/format.js.map +1 -0
  51. package/lib/tar/index.d.ts +8 -0
  52. package/lib/tar/index.d.ts.map +1 -0
  53. package/lib/tar/index.js +6 -0
  54. package/lib/tar/index.js.map +1 -0
  55. package/lib/tar/pax.d.ts +82 -0
  56. package/lib/tar/pax.d.ts.map +1 -0
  57. package/lib/tar/pax.js +185 -0
  58. package/lib/tar/pax.js.map +1 -0
  59. package/lib/types.d.ts +144 -0
  60. package/lib/types.d.ts.map +1 -0
  61. package/lib/types.js +26 -0
  62. package/lib/types.js.map +1 -0
  63. package/package.json +80 -0
package/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ # tar-xz
2
+
3
+ Create and extract tar.xz archives with streaming support for Node.js and buffer-based API for browsers.
4
+
5
+ ## Features
6
+
7
+ - **Node.js streaming API** - Memory-efficient processing of large archives
8
+ - **Browser support** - WASM-powered XZ compression works in any browser
9
+ - **Full TAR support** - POSIX ustar format with PAX extensions for long filenames
10
+ - **TypeScript** - Full type definitions included
11
+ - **Zero dependencies** - Only requires `node-liblzma` (workspace dependency)
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install tar-xz
17
+ # or
18
+ pnpm add tar-xz
19
+ # or
20
+ yarn add tar-xz
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### Node.js
26
+
27
+ ```typescript
28
+ import { create, extract, list } from 'tar-xz';
29
+
30
+ // Create an archive
31
+ await create({
32
+ file: 'archive.tar.xz',
33
+ cwd: '/source/directory',
34
+ files: ['file1.txt', 'subdir/'],
35
+ preset: 6 // compression level (0-9)
36
+ });
37
+
38
+ // List contents
39
+ const entries = await list({ file: 'archive.tar.xz' });
40
+ for (const entry of entries) {
41
+ console.log(entry.name, entry.size);
42
+ }
43
+
44
+ // Extract to disk
45
+ await extract({
46
+ file: 'archive.tar.xz',
47
+ cwd: '/destination',
48
+ strip: 1, // remove leading path component
49
+ filter: (entry) => !entry.name.startsWith('.') // skip hidden files
50
+ });
51
+
52
+ // Extract to memory
53
+ import { extractToMemory } from 'tar-xz';
54
+ const files = await extractToMemory('archive.tar.xz');
55
+ for (const file of files) {
56
+ console.log(file.name, file.content.toString());
57
+ }
58
+ ```
59
+
60
+ ### Browser
61
+
62
+ ```typescript
63
+ import { createTarXz, extractTarXz, listTarXz } from 'tar-xz';
64
+
65
+ // Create from files (e.g., from file input or drag & drop)
66
+ const archive = await createTarXz({
67
+ files: [
68
+ { name: 'hello.txt', content: 'Hello, World!' },
69
+ { name: 'data.json', content: JSON.stringify({ foo: 'bar' }) }
70
+ ],
71
+ preset: 3 // lower preset for browser performance
72
+ });
73
+
74
+ // Download the archive
75
+ const blob = new Blob([archive], { type: 'application/x-xz' });
76
+ const url = URL.createObjectURL(blob);
77
+ // ... trigger download
78
+
79
+ // Extract an archive
80
+ const response = await fetch('archive.tar.xz');
81
+ const data = await response.arrayBuffer();
82
+ const files = await extractTarXz(data);
83
+
84
+ for (const file of files) {
85
+ console.log(file.name, file.data.length);
86
+ }
87
+
88
+ // List contents only (no extraction)
89
+ const entries = await listTarXz(data);
90
+ ```
91
+
92
+ ## API Reference
93
+
94
+ ### Node.js API
95
+
96
+ #### `create(options: CreateOptions): Promise<void>`
97
+
98
+ Create a tar.xz archive from files on disk.
99
+
100
+ Options:
101
+ - `file` - Output archive path
102
+ - `cwd` - Base directory for file paths (default: `process.cwd()`)
103
+ - `files` - Array of file/directory paths to include
104
+ - `preset` - XZ compression preset 0-9 (default: 6)
105
+ - `follow` - Follow symbolic links (default: false)
106
+
107
+ #### `extract(options: ExtractOptions): Promise<TarEntry[]>`
108
+
109
+ Extract a tar.xz archive to disk.
110
+
111
+ Options:
112
+ - `file` - Input archive path
113
+ - `cwd` - Output directory (default: `process.cwd()`)
114
+ - `strip` - Number of leading path components to strip (default: 0)
115
+ - `filter` - Function to filter entries
116
+ - `preserveOwner` - Preserve file ownership (requires root)
117
+
118
+ #### `list(options: ListOptions): Promise<TarEntry[]>`
119
+
120
+ List contents of a tar.xz archive.
121
+
122
+ #### `extractToMemory(file: string, options?): Promise<Array<TarEntry & { content: Buffer }>>`
123
+
124
+ Extract archive to memory without writing to disk.
125
+
126
+ ### Browser API
127
+
128
+ #### `createTarXz(options: BrowserCreateOptions): Promise<Uint8Array>`
129
+
130
+ Create a tar.xz archive from in-memory files.
131
+
132
+ Options:
133
+ - `files` - Array of `{ name, content, mode?, mtime? }`
134
+ - `preset` - XZ compression preset 0-9 (default: 3)
135
+
136
+ #### `extractTarXz(archive: ArrayBuffer | Uint8Array, options?): Promise<ExtractedFile[]>`
137
+
138
+ Extract a tar.xz archive to memory.
139
+
140
+ Options:
141
+ - `strip` - Number of leading path components to strip
142
+ - `filter` - Function to filter entries
143
+
144
+ #### `listTarXz(archive: ArrayBuffer | Uint8Array): Promise<TarEntry[]>`
145
+
146
+ List contents of a tar.xz archive.
147
+
148
+ ## Low-level API
149
+
150
+ For advanced usage, the package also exports low-level TAR utilities:
151
+
152
+ ```typescript
153
+ import {
154
+ BLOCK_SIZE,
155
+ createHeader,
156
+ parseHeader,
157
+ calculatePadding,
158
+ createEndOfArchive,
159
+ needsPaxHeaders,
160
+ createPaxHeaderBlocks,
161
+ } from 'tar-xz';
162
+ ```
163
+
164
+ ## Compression Presets
165
+
166
+ | Preset | Memory Usage | Speed | Ratio |
167
+ |--------|-------------|-------|-------|
168
+ | 1 | ~10 MB | Fastest | Lowest |
169
+ | 3 | ~20 MB | Fast | Good (browser default) |
170
+ | 6 | ~100 MB | Medium | Very Good (Node default) |
171
+ | 9 | ~700 MB | Slowest | Best |
172
+
173
+ For browser usage, presets 1-6 are recommended to avoid memory issues.
174
+
175
+ ## Compatibility
176
+
177
+ Archives created with `tar-xz` are fully compatible with standard tools:
178
+
179
+ ```bash
180
+ # Extract with system tar
181
+ tar -xJf archive.tar.xz
182
+
183
+ # List contents
184
+ tar -tJf archive.tar.xz
185
+
186
+ # Create (for reference)
187
+ tar -cJf archive.tar.xz files/
188
+ ```
189
+
190
+ ## Why tar-xz?
191
+
192
+ The popular `node-tar` package (226M downloads/month) does not support `.tar.xz` files.
193
+ While there are open issues requesting this feature, the maintainer prefers external libraries handle it.
194
+
195
+ `tar-xz` fills this gap by combining:
196
+ - **node-liblzma** for XZ compression (native + WASM)
197
+ - A minimal TAR implementation (no external dependencies)
198
+
199
+ ## License
200
+
201
+ LGPL-3.0 - Same as node-liblzma
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Browser-based TAR creation with XZ compression
3
+ */
4
+ import { type BrowserCreateOptions } from '../types.js';
5
+ /**
6
+ * Create a tar.xz archive in browser
7
+ *
8
+ * @param options - Creation options
9
+ * @returns Compressed archive as Uint8Array
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const archive = await createTarXz({
14
+ * files: [
15
+ * { name: 'hello.txt', content: 'Hello, World!' },
16
+ * { name: 'data.json', content: JSON.stringify({ foo: 'bar' }) }
17
+ * ],
18
+ * preset: 3
19
+ * });
20
+ *
21
+ * // Download the archive
22
+ * const blob = new Blob([archive], { type: 'application/x-xz' });
23
+ * const url = URL.createObjectURL(blob);
24
+ * ```
25
+ */
26
+ export declare function createTarXz(options: BrowserCreateOptions): Promise<Uint8Array>;
27
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/browser/create.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,OAAO,EAAE,KAAK,oBAAoB,EAAgB,MAAM,aAAa,CAAC;AAsCtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,UAAU,CAAC,CAiEpF"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Browser-based TAR creation with XZ compression
3
+ */
4
+ import { xzAsync } from 'node-liblzma';
5
+ import { calculatePadding, createEndOfArchive, createHeader, createPaxHeaderBlocks, needsPaxHeaders, } from '../tar/index.js';
6
+ import { TarEntryType } from '../types.js';
7
+ /**
8
+ * Convert input content to Uint8Array
9
+ */
10
+ async function toUint8Array(content) {
11
+ if (typeof content === 'string') {
12
+ return new TextEncoder().encode(content);
13
+ }
14
+ if (content instanceof Uint8Array) {
15
+ return content;
16
+ }
17
+ if (content instanceof ArrayBuffer) {
18
+ return new Uint8Array(content);
19
+ }
20
+ if (content instanceof Blob) {
21
+ const buffer = await content.arrayBuffer();
22
+ return new Uint8Array(buffer);
23
+ }
24
+ throw new Error('Unsupported content type');
25
+ }
26
+ /**
27
+ * Concatenate multiple Uint8Arrays
28
+ */
29
+ function concatArrays(arrays) {
30
+ const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0);
31
+ const result = new Uint8Array(totalLength);
32
+ let offset = 0;
33
+ for (const arr of arrays) {
34
+ result.set(arr, offset);
35
+ offset += arr.length;
36
+ }
37
+ return result;
38
+ }
39
+ /**
40
+ * Create a tar.xz archive in browser
41
+ *
42
+ * @param options - Creation options
43
+ * @returns Compressed archive as Uint8Array
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const archive = await createTarXz({
48
+ * files: [
49
+ * { name: 'hello.txt', content: 'Hello, World!' },
50
+ * { name: 'data.json', content: JSON.stringify({ foo: 'bar' }) }
51
+ * ],
52
+ * preset: 3
53
+ * });
54
+ *
55
+ * // Download the archive
56
+ * const blob = new Blob([archive], { type: 'application/x-xz' });
57
+ * const url = URL.createObjectURL(blob);
58
+ * ```
59
+ */
60
+ export async function createTarXz(options) {
61
+ const { files, preset = 3 } = options;
62
+ const blocks = [];
63
+ for (const file of files) {
64
+ const content = await toUint8Array(file.content);
65
+ const size = content.length;
66
+ // Normalize name
67
+ let name = file.name.replace(/\\/g, '/');
68
+ // Determine if it's a directory (ends with / and has no content)
69
+ const isDir = name.endsWith('/') && size === 0;
70
+ const type = isDir ? TarEntryType.DIRECTORY : TarEntryType.FILE;
71
+ // Check if PAX headers are needed
72
+ if (needsPaxHeaders({ name, size })) {
73
+ const paxBlocks = createPaxHeaderBlocks(name, {
74
+ path: name,
75
+ size,
76
+ });
77
+ blocks.push(...paxBlocks);
78
+ // Truncate name for the regular header
79
+ name = name.slice(-100);
80
+ }
81
+ // Create header
82
+ const mtime = file.mtime
83
+ ? typeof file.mtime === 'number'
84
+ ? file.mtime
85
+ : Math.floor(file.mtime.getTime() / 1000)
86
+ : Math.floor(Date.now() / 1000);
87
+ const header = createHeader({
88
+ name,
89
+ type,
90
+ size,
91
+ mode: file.mode ?? (isDir ? 0o755 : 0o644),
92
+ mtime,
93
+ });
94
+ blocks.push(header);
95
+ // Add content
96
+ if (size > 0) {
97
+ blocks.push(content);
98
+ // Add padding
99
+ const padding = calculatePadding(size);
100
+ if (padding > 0) {
101
+ blocks.push(new Uint8Array(padding));
102
+ }
103
+ }
104
+ }
105
+ // Add end-of-archive marker
106
+ blocks.push(createEndOfArchive());
107
+ // Concatenate all blocks into TAR
108
+ const tarData = concatArrays(blocks);
109
+ // Compress with XZ
110
+ // Cast to any because WASM accepts Uint8Array but types are defined for Node.js Buffer
111
+ return xzAsync(tarData, { preset });
112
+ }
113
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/browser/create.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAA6B,YAAY,EAAE,MAAM,aAAa,CAAC;AAEtE;;GAEG;AACH,KAAK,UAAU,YAAY,CACzB,OAAiD;IAEjD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,OAAO,YAAY,UAAU,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,I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CAAC,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAErB,cAAc;YACd,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;gBAChB,MAAM,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IAED,4BAA4B;IAC5B,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAElC,kCAAkC;IAClC,MAAM,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;IAErC,mBAAmB;IACnB,uFAAuF;IACvF,OAAO,OAAO,CAAC,OAAmD,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAClF,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Browser-based TAR extraction with XZ decompression
3
+ */
4
+ import { type BrowserExtractOptions, type ExtractedFile } from '../types.js';
5
+ /**
6
+ * Extract a tar.xz archive in browser
7
+ *
8
+ * @param archive - Compressed archive data (ArrayBuffer or Uint8Array)
9
+ * @param options - Extraction options
10
+ * @returns Array of extracted files
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const response = await fetch('archive.tar.xz');
15
+ * const data = await response.arrayBuffer();
16
+ * const files = await extractTarXz(data);
17
+ *
18
+ * for (const file of files) {
19
+ * console.log(file.name, file.data.length);
20
+ * }
21
+ * ```
22
+ */
23
+ export declare function extractTarXz(archive: ArrayBuffer | Uint8Array, options?: BrowserExtractOptions): Promise<ExtractedFile[]>;
24
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../src/browser/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAGnB,MAAM,aAAa,CAAC;AA4ErB;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,WAAW,GAAG,UAAU,EACjC,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,aAAa,EAAE,CAAC,CAoC1B"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Browser-based TAR extraction with XZ decompression
3
+ */
4
+ import { unxzAsync } from 'node-liblzma';
5
+ import { applyPaxAttributes, BLOCK_SIZE, calculatePadding, isEmptyBlock, parseHeader, parsePaxData, } from '../tar/index.js';
6
+ import { TarEntryType, } from '../types.js';
7
+ /**
8
+ * Parse TAR data into entries
9
+ */
10
+ function parseTar(data) {
11
+ const entries = [];
12
+ let offset = 0;
13
+ let paxAttrs = null;
14
+ let emptyBlockCount = 0;
15
+ while (offset + BLOCK_SIZE <= data.length) {
16
+ const headerBlock = data.subarray(offset, offset + BLOCK_SIZE);
17
+ offset += BLOCK_SIZE;
18
+ // Check for end-of-archive
19
+ if (isEmptyBlock(headerBlock)) {
20
+ emptyBlockCount++;
21
+ if (emptyBlockCount >= 2) {
22
+ break;
23
+ }
24
+ continue;
25
+ }
26
+ emptyBlockCount = 0;
27
+ // Parse header
28
+ let entry = parseHeader(headerBlock);
29
+ if (!entry) {
30
+ continue;
31
+ }
32
+ // Handle PAX headers
33
+ if (entry.type === TarEntryType.PAX_HEADER) {
34
+ const paxSize = entry.size;
35
+ const paxData = data.subarray(offset, offset + paxSize);
36
+ offset += paxSize + calculatePadding(paxSize);
37
+ paxAttrs = parsePaxData(paxData);
38
+ continue;
39
+ }
40
+ if (entry.type === TarEntryType.PAX_GLOBAL) {
41
+ offset += entry.size + calculatePadding(entry.size);
42
+ continue;
43
+ }
44
+ // Apply PAX attributes if present
45
+ if (paxAttrs) {
46
+ entry = applyPaxAttributes(entry, paxAttrs);
47
+ paxAttrs = null;
48
+ }
49
+ // Extract content
50
+ const contentData = entry.size > 0 ? data.subarray(offset, offset + entry.size) : new Uint8Array(0);
51
+ offset += entry.size + calculatePadding(entry.size);
52
+ entries.push({ ...entry, data: contentData });
53
+ }
54
+ return entries;
55
+ }
56
+ /**
57
+ * Strip leading path components from a path
58
+ */
59
+ function stripPath(filePath, strip) {
60
+ if (strip <= 0) {
61
+ return filePath;
62
+ }
63
+ const parts = filePath.split('/');
64
+ return parts.slice(strip).join('/');
65
+ }
66
+ /**
67
+ * Extract a tar.xz archive in browser
68
+ *
69
+ * @param archive - Compressed archive data (ArrayBuffer or Uint8Array)
70
+ * @param options - Extraction options
71
+ * @returns Array of extracted files
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const response = await fetch('archive.tar.xz');
76
+ * const data = await response.arrayBuffer();
77
+ * const files = await extractTarXz(data);
78
+ *
79
+ * for (const file of files) {
80
+ * console.log(file.name, file.data.length);
81
+ * }
82
+ * ```
83
+ */
84
+ export async function extractTarXz(archive, options = {}) {
85
+ const { strip = 0, filter } = options;
86
+ // Convert to Uint8Array if needed
87
+ const archiveData = archive instanceof Uint8Array ? archive : new Uint8Array(archive);
88
+ // Decompress XZ
89
+ // Cast to any because WASM accepts Uint8Array but types are defined for Node.js Buffer
90
+ const tarData = await unxzAsync(archiveData);
91
+ // Parse TAR
92
+ const entries = parseTar(tarData);
93
+ // Apply strip and filter
94
+ const results = [];
95
+ for (const entry of entries) {
96
+ const strippedName = stripPath(entry.name, strip);
97
+ if (!strippedName) {
98
+ continue;
99
+ }
100
+ const strippedEntry = { ...entry, name: strippedName };
101
+ if (filter && !filter(strippedEntry)) {
102
+ continue;
103
+ }
104
+ results.push({
105
+ name: strippedName,
106
+ data: entry.data,
107
+ entry: strippedEntry,
108
+ });
109
+ }
110
+ return results;
111
+ }
112
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/browser/extract.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,kBAAkB,EAClB,UAAU,E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AO,YAAY,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IAEtF,gBAAgB;IAChB,uFAAuF;IACvF,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,WAAyD,CAAC,CAAC;IAE3F,YAAY;IACZ,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IAElC,yBAAyB;IACzB,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAClD,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,SAAS;QACX,CAAC;QAED,MAAM,aAAa,GAAG,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;QAEvD,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YACrC,SAAS;QACX,CAAC;QAED,OAAO,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,aAAa;SACrB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Browser API for tar.xz archives
3
+ */
4
+ export { createTarXz } from './create.js';
5
+ export { extractTarXz } from './extract.js';
6
+ export { listTarXz } from './list.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Browser API for tar.xz archives
3
+ */
4
+ export { createTarXz } from './create.js';
5
+ export { extractTarXz } from './extract.js';
6
+ export { listTarXz } from './list.js';
7
+ //# sourceMappingURL=index.js.map