tar-utils 3.1.2 → 3.1.3
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/.versionbot/CHANGELOG.yml +48 -1
- package/CHANGELOG.md +5 -0
- package/build/index.d.ts +10 -6
- package/build/index.js.map +1 -1
- package/lib/index.ts +43 -14
- package/package.json +4 -5
- package/tests/tests.ts +16 -15
- package/tests/types/tar-stream.ts +109 -0
- package/tests/types/tsconfig.json +8 -0
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
- commits:
|
|
2
|
+
- subject: Use tar-stream's bundled types
|
|
3
|
+
hash: 6d8297feeb0b1f9fae085405396b1be899151b78
|
|
4
|
+
body: >
|
|
5
|
+
tar-stream 3.2.1 started shipping its own (streamx-based) typings, which
|
|
6
|
+
|
|
7
|
+
take precedence over `@types/tar-stream`. A fresh install resolves
|
|
8
|
+
|
|
9
|
+
`tar-stream@^3.1.6` to 3.2.2, so `tsc` (and so `npm install` through
|
|
10
|
+
|
|
11
|
+
`prepare`) failed: `tar.Headers` and `tar.Callback` no longer exist, and
|
|
12
|
+
|
|
13
|
+
entry streams are streamx Readables rather than node ones. Consumers got
|
|
14
|
+
|
|
15
|
+
`any` for those types in our emitted declarations, or errors without
|
|
16
|
+
|
|
17
|
+
skipLibCheck.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
Require tar-stream ^3.2.2 (the first release that also requires a
|
|
21
|
+
|
|
22
|
+
streamx version with typings), drop `@types/tar-stream`, and use
|
|
23
|
+
|
|
24
|
+
`tar.Header` and the entry stream and callback types from
|
|
25
|
+
|
|
26
|
+
`tar.ExtractEvents`, exported as `TarEntryStream` and
|
|
27
|
+
`TarEntryCallback`.
|
|
28
|
+
|
|
29
|
+
`streamToBuffer`, `drainStream`, `pipePromise` and `cloneTarStream` now
|
|
30
|
+
|
|
31
|
+
accept streamx streams (such as `tar.Pack` and entry streams) as well as
|
|
32
|
+
|
|
33
|
+
node ones. `multicastStream` keeps requiring a node Readable, as a
|
|
34
|
+
|
|
35
|
+
streamx Readable can only pipe to one destination.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
Add type tests under `tests/types`, checked by `npm run lint` with both
|
|
39
|
+
|
|
40
|
+
the dev and a strict tsconfig, which also type-check the tests now.
|
|
41
|
+
footer:
|
|
42
|
+
Change-type: patch
|
|
43
|
+
change-type: patch
|
|
44
|
+
author: Pagan Gazzard
|
|
45
|
+
version: 3.1.3
|
|
46
|
+
title: ""
|
|
47
|
+
date: 2026-11-13T13:58:38.156Z
|
|
1
48
|
- commits:
|
|
2
49
|
- subject: "Add id-token: write permission for NPM OIDC publishing"
|
|
3
50
|
hash: 1dd1deef89bdb727d740b5caad5da72d041c9081
|
|
@@ -10,7 +57,7 @@
|
|
|
10
57
|
author: Kyle Harding
|
|
11
58
|
version: 3.1.2
|
|
12
59
|
title: ""
|
|
13
|
-
date: 2026-02-19T13:
|
|
60
|
+
date: 2026-02-19T13:43:29.594Z
|
|
14
61
|
- commits:
|
|
15
62
|
- subject: Simplify `pipePromise` using the built in `Stream.promises.pipeline`
|
|
16
63
|
hash: 2f640ab45c041eb2e917e274f56c9642015319d3
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file
|
|
|
4
4
|
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
|
|
5
5
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
# v3.1.3
|
|
8
|
+
## (2026-11-13)
|
|
9
|
+
|
|
10
|
+
* Use tar-stream's bundled types [Pagan Gazzard]
|
|
11
|
+
|
|
7
12
|
# v3.1.2
|
|
8
13
|
## (2026-02-19)
|
|
9
14
|
|
package/build/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { type Readable, type Writable } from 'stream';
|
|
2
2
|
import * as tar from 'tar-stream';
|
|
3
|
+
export type TarEntryStream = tar.ExtractEvents['entry'][1];
|
|
4
|
+
export type TarEntryCallback = tar.ExtractEvents['entry'][2];
|
|
5
|
+
export type StreamxReadable = tar.ExtractEvents['pipe'][0];
|
|
6
|
+
export type ReadableStreamLike = Readable | StreamxReadable;
|
|
3
7
|
export declare function normalizeTarEntry(name: string): string;
|
|
4
|
-
export declare function streamToBuffer(stream:
|
|
5
|
-
export declare function drainStream(stream:
|
|
6
|
-
export declare function pipePromise<WritableSub extends Writable>(pipeFrom:
|
|
7
|
-
export declare function cloneTarStream(sourceTarStream:
|
|
8
|
-
onEntry?: (pack: tar.Pack, header: tar.
|
|
8
|
+
export declare function streamToBuffer(stream: ReadableStreamLike): Promise<Buffer>;
|
|
9
|
+
export declare function drainStream(stream: ReadableStreamLike): Promise<void>;
|
|
10
|
+
export declare function pipePromise<WritableSub extends Writable>(pipeFrom: ReadableStreamLike, pipeTo: WritableSub): Promise<WritableSub>;
|
|
11
|
+
export declare function cloneTarStream(sourceTarStream: ReadableStreamLike, opts?: {
|
|
12
|
+
onEntry?: (pack: tar.Pack, header: tar.Header, stream: TarEntryStream) => void | Promise<void>;
|
|
9
13
|
onFinish?: (pack: tar.Pack) => void | Promise<void>;
|
|
10
14
|
}): Promise<tar.Pack>;
|
|
11
|
-
export declare function throughTarStream(onEntry: (pack: tar.Pack, header: tar.
|
|
15
|
+
export declare function throughTarStream(onEntry: (pack: tar.Pack, header: tar.Header, stream: TarEntryStream, next: TarEntryCallback) => void | Promise<void>): readonly [tar.Extract<tar.ExtractEvents>, tar.Pack];
|
|
12
16
|
export declare function multicastStream(fromStream: Readable, toStreams: Writable[]): Promise<void>;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;AA8DA,8CAWC;AAMD,wCAyBC;AAUD,kCAaC;AAYD,kCAMC;AAgBD,wCA2DC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AAkC,CAAC;gBACvC,IAAI,CAAC;oBACJ,MAAM,IAAI,OAAO,CAAO,CAAC,eAAe,EAAE,EAAE,CAC3C,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,GAAG,eAAe,CAAC,CAAC,CACnD,CAAC;oBACF,OAAO;gBACR,CAAC;wBAAS,CAAC;oBACV,QAAQ,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,IAAI,IAAI,CAAC,CAAC;gBACrD,CAAC;YACF,CAAC,CAAC,CACF;iBACC,IAAI,CAAC,GAAG,EAAE;gBACV,OAAO,EAAE,CAAC;YACX,CAAC,CAAC;iBACD,KAAK,CAAC,MAAM,CAAC,CAAC;YAEhB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;YAC3C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBAClC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC9B,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;YAAS,CAAC;QACV,UAAU,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC;QACpD,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC9B,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,CACjD,CAAC;IACH,CAAC;AACF,CAAC"}
|
package/lib/index.ts
CHANGED
|
@@ -22,6 +22,31 @@ function noop() {
|
|
|
22
22
|
// noop
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* The stream of an entry's contents, as passed to tar-stream's extract
|
|
27
|
+
* 'entry' listener (a streamx Readable, not a node one)
|
|
28
|
+
*/
|
|
29
|
+
export type TarEntryStream = tar.ExtractEvents['entry'][1];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The callback that tar-stream's extract 'entry' listener must call when it
|
|
33
|
+
* is done with an entry, optionally with an error
|
|
34
|
+
*/
|
|
35
|
+
export type TarEntryCallback = tar.ExtractEvents['entry'][2];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A streamx Readable, the base of tar-stream's streams (tar.Pack and
|
|
39
|
+
* TarEntryStream). tar-stream doesn't export it by name, but it is the
|
|
40
|
+
* source type of the 'pipe' event of its Extract (streamx Writable) stream.
|
|
41
|
+
*/
|
|
42
|
+
export type StreamxReadable = tar.ExtractEvents['pipe'][0];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A readable stream, either a node one or a streamx one such as a tar.Pack
|
|
46
|
+
* or a TarEntryStream
|
|
47
|
+
*/
|
|
48
|
+
export type ReadableStreamLike = Readable | StreamxReadable;
|
|
49
|
+
|
|
25
50
|
/**
|
|
26
51
|
* normalizeTarEntry: Depending on how the tar archive was created,
|
|
27
52
|
* filenames can be presented in several different forms, and this function
|
|
@@ -52,8 +77,10 @@ export function normalizeTarEntry(name: string): string {
|
|
|
52
77
|
* streamToBuffer: Given a stream, read it into a buffer
|
|
53
78
|
* @param stream
|
|
54
79
|
*/
|
|
55
|
-
export async function streamToBuffer(
|
|
56
|
-
|
|
80
|
+
export async function streamToBuffer(
|
|
81
|
+
stream: ReadableStreamLike,
|
|
82
|
+
): Promise<Buffer> {
|
|
83
|
+
let onData: ((data: unknown) => void) | undefined;
|
|
57
84
|
let onError: ((error: Error) => void) | undefined;
|
|
58
85
|
let onEnd: (() => void) | undefined;
|
|
59
86
|
try {
|
|
@@ -67,7 +94,7 @@ export async function streamToBuffer(stream: Readable): Promise<Buffer> {
|
|
|
67
94
|
);
|
|
68
95
|
stream.on('error', (onError = reject));
|
|
69
96
|
// adding a 'data' listener switches the stream to flowing mode
|
|
70
|
-
stream.on('data', (onData = (data
|
|
97
|
+
stream.on('data', (onData = (data) => chunks.push(data as Buffer)));
|
|
71
98
|
});
|
|
72
99
|
return Buffer.concat(buffers);
|
|
73
100
|
} finally {
|
|
@@ -85,7 +112,7 @@ export async function streamToBuffer(stream: Readable): Promise<Buffer> {
|
|
|
85
112
|
* @param stream A readable stream to be drained
|
|
86
113
|
* @return A promise that resolves when the stream is drained
|
|
87
114
|
*/
|
|
88
|
-
export async function drainStream(stream:
|
|
115
|
+
export async function drainStream(stream: ReadableStreamLike): Promise<void> {
|
|
89
116
|
let onError: ((error: Error) => void) | undefined;
|
|
90
117
|
let onEnd: (() => void) | undefined;
|
|
91
118
|
try {
|
|
@@ -111,7 +138,7 @@ export async function drainStream(stream: Readable): Promise<void> {
|
|
|
111
138
|
* @param pipeTo Stream to pipe to
|
|
112
139
|
*/
|
|
113
140
|
export async function pipePromise<WritableSub extends Writable>(
|
|
114
|
-
pipeFrom:
|
|
141
|
+
pipeFrom: ReadableStreamLike,
|
|
115
142
|
pipeTo: WritableSub,
|
|
116
143
|
): Promise<WritableSub> {
|
|
117
144
|
await Stream.promises.pipeline(pipeFrom, pipeTo);
|
|
@@ -133,12 +160,12 @@ export async function pipePromise<WritableSub extends Writable>(
|
|
|
133
160
|
* promise which will then be awaited for.
|
|
134
161
|
*/
|
|
135
162
|
export async function cloneTarStream(
|
|
136
|
-
sourceTarStream:
|
|
163
|
+
sourceTarStream: ReadableStreamLike,
|
|
137
164
|
opts?: {
|
|
138
165
|
onEntry?: (
|
|
139
166
|
pack: tar.Pack,
|
|
140
|
-
header: tar.
|
|
141
|
-
stream:
|
|
167
|
+
header: tar.Header,
|
|
168
|
+
stream: TarEntryStream,
|
|
142
169
|
) => void | Promise<void>;
|
|
143
170
|
onFinish?: (pack: tar.Pack) => void | Promise<void>;
|
|
144
171
|
},
|
|
@@ -150,7 +177,7 @@ export async function cloneTarStream(
|
|
|
150
177
|
await opts.onEntry($pack, header, stream);
|
|
151
178
|
callback();
|
|
152
179
|
} catch (err) {
|
|
153
|
-
callback(err);
|
|
180
|
+
callback(err as Error);
|
|
154
181
|
}
|
|
155
182
|
} else {
|
|
156
183
|
stream.pipe($pack.entry(header, callback));
|
|
@@ -183,7 +210,9 @@ export async function cloneTarStream(
|
|
|
183
210
|
reject(err as Error);
|
|
184
211
|
}
|
|
185
212
|
});
|
|
186
|
-
|
|
213
|
+
// Node's and streamx's pipe() both accept either kind of writable stream,
|
|
214
|
+
// but TS can't call pipe() on the union of their signatures
|
|
215
|
+
(sourceTarStream as StreamxReadable).pipe(extract);
|
|
187
216
|
});
|
|
188
217
|
} finally {
|
|
189
218
|
sourceTarStream.removeListener('error', sourceTarStreamOnError ?? noop);
|
|
@@ -205,9 +234,9 @@ export async function cloneTarStream(
|
|
|
205
234
|
export function throughTarStream(
|
|
206
235
|
onEntry: (
|
|
207
236
|
pack: tar.Pack,
|
|
208
|
-
header: tar.
|
|
209
|
-
stream:
|
|
210
|
-
next:
|
|
237
|
+
header: tar.Header,
|
|
238
|
+
stream: TarEntryStream,
|
|
239
|
+
next: TarEntryCallback,
|
|
211
240
|
) => void | Promise<void>,
|
|
212
241
|
) {
|
|
213
242
|
const extract = tar.extract();
|
|
@@ -217,7 +246,7 @@ export function throughTarStream(
|
|
|
217
246
|
try {
|
|
218
247
|
await onEntry(pack, header, stream, next);
|
|
219
248
|
} catch (err) {
|
|
220
|
-
next(err);
|
|
249
|
+
next(err as Error);
|
|
221
250
|
}
|
|
222
251
|
})
|
|
223
252
|
.on('error', (err) => {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tar-utils",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "A collection of utilities which expose oft-used patterns when working with tar archives in node",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "npm run lint && npx mocha",
|
|
9
|
-
"lint": "balena-lint -t tsconfig.dev.json lib tests",
|
|
9
|
+
"lint": "balena-lint -t tsconfig.dev.json lib tests && tsc --noEmit -p tsconfig.dev.json && tsc --noEmit -p tests/types/tsconfig.json",
|
|
10
10
|
"lint-fix": "balena-lint -t tsconfig.dev.json --fix lib tests",
|
|
11
11
|
"prepublish": "require-npm4-to-publish",
|
|
12
12
|
"prepare": "tsc"
|
|
@@ -22,14 +22,13 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/resin-io-modules/node-tar-utils#readme",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"tar-stream": "^3.
|
|
25
|
+
"tar-stream": "^3.2.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@balena/lint": "^8.2.8",
|
|
29
29
|
"@types/chai": "^4.3.5",
|
|
30
30
|
"@types/mocha": "^10.0.1",
|
|
31
31
|
"@types/node": "^16.18.38",
|
|
32
|
-
"@types/tar-stream": "^3.1.4",
|
|
33
32
|
"chai": "^4.3.7",
|
|
34
33
|
"mocha": "^11.0.0",
|
|
35
34
|
"require-npm4-to-publish": "^1.0.0",
|
|
@@ -49,6 +48,6 @@
|
|
|
49
48
|
"node": ">=16.13.0"
|
|
50
49
|
},
|
|
51
50
|
"versionist": {
|
|
52
|
-
"publishedAt": "2026-
|
|
51
|
+
"publishedAt": "2026-11-13T13:58:38.209Z"
|
|
53
52
|
}
|
|
54
53
|
}
|
package/tests/tests.ts
CHANGED
|
@@ -107,25 +107,26 @@ describe('cloneTarStream', function () {
|
|
|
107
107
|
];
|
|
108
108
|
|
|
109
109
|
const pack = await TarUtils.cloneTarStream(sourceTarStream);
|
|
110
|
-
await new Promise((resolve, reject) => {
|
|
110
|
+
await new Promise<void>((resolve, reject) => {
|
|
111
111
|
let i = 0;
|
|
112
112
|
const extract = tar.extract();
|
|
113
113
|
pack.on('error', reject);
|
|
114
114
|
extract.on('error', reject);
|
|
115
|
-
extract.on(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
)
|
|
128
|
-
|
|
115
|
+
extract.on('entry', (header, stream, callback) => {
|
|
116
|
+
try {
|
|
117
|
+
const [expectedName, expectedSize] = expectedEntries[i++];
|
|
118
|
+
expect(header.name).to.equal(expectedName);
|
|
119
|
+
expect(header.size).to.equal(expectedSize);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
reject(error as Error);
|
|
122
|
+
}
|
|
123
|
+
TarUtils.drainStream(stream).then(() => {
|
|
124
|
+
callback();
|
|
125
|
+
}, callback);
|
|
126
|
+
});
|
|
127
|
+
extract.once('finish', () => {
|
|
128
|
+
resolve();
|
|
129
|
+
});
|
|
129
130
|
pack.pipe(extract);
|
|
130
131
|
});
|
|
131
132
|
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Balena Ltd.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// Type-only tests: checked by `tsc -p tsconfig.dev.json` (npm run lint), never
|
|
19
|
+
// run. They check that tar-utils accepts tar-stream's own (streamx) streams
|
|
20
|
+
// and passes tar-stream's types to callbacks.
|
|
21
|
+
|
|
22
|
+
import { PassThrough, type Readable, type Writable } from 'stream';
|
|
23
|
+
import type * as tar from 'tar-stream';
|
|
24
|
+
|
|
25
|
+
import * as TarUtils from '../../lib';
|
|
26
|
+
|
|
27
|
+
// Type-only assertion: the argument must be assignable to T
|
|
28
|
+
function expectType<T>(value: T): T {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare const nodeReadable: Readable;
|
|
33
|
+
declare const nodeWritable: Writable;
|
|
34
|
+
declare const pack: tar.Pack;
|
|
35
|
+
declare const entryStream: TarUtils.TarEntryStream;
|
|
36
|
+
|
|
37
|
+
export async function streamUtils() {
|
|
38
|
+
expectType<Buffer>(await TarUtils.streamToBuffer(entryStream));
|
|
39
|
+
expectType<Buffer>(await TarUtils.streamToBuffer(nodeReadable));
|
|
40
|
+
expectType<Buffer>(await TarUtils.streamToBuffer(pack));
|
|
41
|
+
// @ts-expect-error not a stream
|
|
42
|
+
await TarUtils.streamToBuffer('foo');
|
|
43
|
+
|
|
44
|
+
await TarUtils.drainStream(entryStream);
|
|
45
|
+
await TarUtils.drainStream(nodeReadable);
|
|
46
|
+
|
|
47
|
+
expectType<Writable>(await TarUtils.pipePromise(pack, nodeWritable));
|
|
48
|
+
expectType<PassThrough>(
|
|
49
|
+
await TarUtils.pipePromise(nodeReadable, new PassThrough()),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
// streamx streams (like tar.Pack) can only pipe to one destination
|
|
53
|
+
// @ts-expect-error multicastStream needs a node Readable
|
|
54
|
+
await TarUtils.multicastStream(pack, [nodeWritable, new PassThrough()]);
|
|
55
|
+
await TarUtils.multicastStream(nodeReadable, [nodeWritable]);
|
|
56
|
+
|
|
57
|
+
expectType<tar.Pack>(await TarUtils.cloneTarStream(pack));
|
|
58
|
+
expectType<tar.Pack>(await TarUtils.cloneTarStream(nodeReadable));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function cloneTarStreamCallbacks() {
|
|
62
|
+
await TarUtils.cloneTarStream(pack, {
|
|
63
|
+
onEntry: async ($pack, header, stream) => {
|
|
64
|
+
expectType<tar.Pack>($pack);
|
|
65
|
+
expectType<tar.Header>(header);
|
|
66
|
+
expectType<number>(header.size);
|
|
67
|
+
// @ts-expect-error header is a tar.Header, not any
|
|
68
|
+
expectType<string>(header);
|
|
69
|
+
expectType<TarUtils.TarEntryStream>(stream);
|
|
70
|
+
// @ts-expect-error the entry stream is a streamx Readable, not a node one
|
|
71
|
+
expectType<Readable>(stream);
|
|
72
|
+
$pack.entry(
|
|
73
|
+
{ ...header, name: `a/${header.name}` },
|
|
74
|
+
await TarUtils.streamToBuffer(stream),
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
onFinish: ($pack) => {
|
|
78
|
+
$pack.entry({ name: 'extra' }, 'contents');
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function throughTarStreamCallbacks() {
|
|
84
|
+
const [extract, outPack] = TarUtils.throughTarStream(
|
|
85
|
+
async ($pack, header, stream, next) => {
|
|
86
|
+
expectType<tar.Pack>($pack);
|
|
87
|
+
expectType<tar.Header>(header);
|
|
88
|
+
// @ts-expect-error header is a tar.Header, not any
|
|
89
|
+
expectType<string>(header);
|
|
90
|
+
expectType<TarUtils.TarEntryStream>(stream);
|
|
91
|
+
expectType<TarUtils.TarEntryCallback>(next);
|
|
92
|
+
if (header.name === 'skip') {
|
|
93
|
+
await TarUtils.drainStream(stream);
|
|
94
|
+
next();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (header.name === 'error') {
|
|
98
|
+
next(new Error('error'));
|
|
99
|
+
next(null);
|
|
100
|
+
// @ts-expect-error next only accepts an Error (or nothing/null)
|
|
101
|
+
next('error');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
stream.pipe($pack.entry({ ...header, name: `a/${header.name}` }, next));
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
expectType<tar.Extract>(extract);
|
|
108
|
+
expectType<tar.Pack>(outPack);
|
|
109
|
+
}
|