tar-utils 3.1.4 → 3.1.5
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/CHANGELOG.md +5 -0
- package/package.json +7 -2
- package/.github/workflows/flowzone.yml +0 -33
- package/.versionbot/CHANGELOG.yml +0 -309
- package/tests/test-files/cloneTarStream.tar +0 -0
- package/tests/tests.ts +0 -261
- package/tests/types/tar-stream.ts +0 -109
- package/tests/types/tsconfig.json +0 -8
- package/tsconfig.dev.json +0 -7
- package/tsconfig.json +0 -23
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.5
|
|
8
|
+
## (2026-11-13)
|
|
9
|
+
|
|
10
|
+
* Only publish the build output and its sources [Pagan Gazzard]
|
|
11
|
+
|
|
7
12
|
# v3.1.4
|
|
8
13
|
## (2026-11-13)
|
|
9
14
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tar-utils",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.5",
|
|
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
|
+
"files": [
|
|
8
|
+
"build/",
|
|
9
|
+
"lib/",
|
|
10
|
+
"CHANGELOG.md"
|
|
11
|
+
],
|
|
7
12
|
"scripts": {
|
|
8
13
|
"test": "npm run lint && npx mocha",
|
|
9
14
|
"lint": "balena-lint -t tsconfig.dev.json lib tests && tsc --noEmit -p tsconfig.dev.json && tsc --noEmit -p tests/types/tsconfig.json",
|
|
@@ -48,6 +53,6 @@
|
|
|
48
53
|
"node": ">=16.13.0"
|
|
49
54
|
},
|
|
50
55
|
"versionist": {
|
|
51
|
-
"publishedAt": "2026-11-13T17:
|
|
56
|
+
"publishedAt": "2026-11-13T17:36:09.518Z"
|
|
52
57
|
}
|
|
53
58
|
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
name: Flowzone
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
types: [opened, synchronize, closed]
|
|
6
|
-
branches:
|
|
7
|
-
- "main"
|
|
8
|
-
- "master"
|
|
9
|
-
pull_request_target:
|
|
10
|
-
types: [opened, synchronize, closed]
|
|
11
|
-
branches:
|
|
12
|
-
- "main"
|
|
13
|
-
- "master"
|
|
14
|
-
|
|
15
|
-
permissions:
|
|
16
|
-
id-token: write
|
|
17
|
-
contents: read
|
|
18
|
-
packages: read
|
|
19
|
-
|
|
20
|
-
jobs:
|
|
21
|
-
flowzone:
|
|
22
|
-
name: Flowzone
|
|
23
|
-
uses: product-os/flowzone/.github/workflows/flowzone.yml@master
|
|
24
|
-
# prevent duplicate workflow executions for pull_request and pull_request_target
|
|
25
|
-
if: |
|
|
26
|
-
(
|
|
27
|
-
github.event.pull_request.head.repo.full_name == github.repository &&
|
|
28
|
-
github.event_name == 'pull_request'
|
|
29
|
-
) || (
|
|
30
|
-
github.event.pull_request.head.repo.full_name != github.repository &&
|
|
31
|
-
github.event_name == 'pull_request_target'
|
|
32
|
-
)
|
|
33
|
-
secrets: inherit
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
- commits:
|
|
2
|
-
- subject: Point `bugs` and `homepage` at the balena-io-modules repository
|
|
3
|
-
hash: 51f4396bf66e26b11bc4e5cff8f5e054077c2998
|
|
4
|
-
body: |
|
|
5
|
-
3e260b2 updated `repository.url` but left these on the old
|
|
6
|
-
resin-io-modules organisation, which only works through GitHub's
|
|
7
|
-
redirect.
|
|
8
|
-
footer:
|
|
9
|
-
Change-type: patch
|
|
10
|
-
change-type: patch
|
|
11
|
-
author: Pagan Gazzard
|
|
12
|
-
version: 3.1.4
|
|
13
|
-
title: ""
|
|
14
|
-
date: 2026-11-13T17:22:21.449Z
|
|
15
|
-
- commits:
|
|
16
|
-
- subject: Use tar-stream's bundled types
|
|
17
|
-
hash: 6d8297feeb0b1f9fae085405396b1be899151b78
|
|
18
|
-
body: >
|
|
19
|
-
tar-stream 3.2.1 started shipping its own (streamx-based) typings, which
|
|
20
|
-
|
|
21
|
-
take precedence over `@types/tar-stream`. A fresh install resolves
|
|
22
|
-
|
|
23
|
-
`tar-stream@^3.1.6` to 3.2.2, so `tsc` (and so `npm install` through
|
|
24
|
-
|
|
25
|
-
`prepare`) failed: `tar.Headers` and `tar.Callback` no longer exist, and
|
|
26
|
-
|
|
27
|
-
entry streams are streamx Readables rather than node ones. Consumers got
|
|
28
|
-
|
|
29
|
-
`any` for those types in our emitted declarations, or errors without
|
|
30
|
-
|
|
31
|
-
skipLibCheck.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Require tar-stream ^3.2.2 (the first release that also requires a
|
|
35
|
-
|
|
36
|
-
streamx version with typings), drop `@types/tar-stream`, and use
|
|
37
|
-
|
|
38
|
-
`tar.Header` and the entry stream and callback types from
|
|
39
|
-
|
|
40
|
-
`tar.ExtractEvents`, exported as `TarEntryStream` and
|
|
41
|
-
`TarEntryCallback`.
|
|
42
|
-
|
|
43
|
-
`streamToBuffer`, `drainStream`, `pipePromise` and `cloneTarStream` now
|
|
44
|
-
|
|
45
|
-
accept streamx streams (such as `tar.Pack` and entry streams) as well as
|
|
46
|
-
|
|
47
|
-
node ones. `multicastStream` keeps requiring a node Readable, as a
|
|
48
|
-
|
|
49
|
-
streamx Readable can only pipe to one destination.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Add type tests under `tests/types`, checked by `npm run lint` with both
|
|
53
|
-
|
|
54
|
-
the dev and a strict tsconfig, which also type-check the tests now.
|
|
55
|
-
footer:
|
|
56
|
-
Change-type: patch
|
|
57
|
-
change-type: patch
|
|
58
|
-
author: Pagan Gazzard
|
|
59
|
-
version: 3.1.3
|
|
60
|
-
title: ""
|
|
61
|
-
date: 2026-11-13T17:12:11.107Z
|
|
62
|
-
- commits:
|
|
63
|
-
- subject: "Add id-token: write permission for NPM OIDC publishing"
|
|
64
|
-
hash: 1dd1deef89bdb727d740b5caad5da72d041c9081
|
|
65
|
-
body: ""
|
|
66
|
-
footer:
|
|
67
|
-
Change-type: patch
|
|
68
|
-
change-type: patch
|
|
69
|
-
Signed-off-by: Kyle Harding <kyle@balena.io>
|
|
70
|
-
signed-off-by: Kyle Harding <kyle@balena.io>
|
|
71
|
-
author: Kyle Harding
|
|
72
|
-
version: 3.1.2
|
|
73
|
-
title: ""
|
|
74
|
-
date: 2026-02-19T13:43:29.594Z
|
|
75
|
-
- commits:
|
|
76
|
-
- subject: Simplify `pipePromise` using the built in `Stream.promises.pipeline`
|
|
77
|
-
hash: 2f640ab45c041eb2e917e274f56c9642015319d3
|
|
78
|
-
body: ""
|
|
79
|
-
footer:
|
|
80
|
-
Change-type: patch
|
|
81
|
-
change-type: patch
|
|
82
|
-
author: Pagan Gazzard
|
|
83
|
-
version: 3.1.1
|
|
84
|
-
title: ""
|
|
85
|
-
date: 2025-09-25T13:54:31.074Z
|
|
86
|
-
- commits:
|
|
87
|
-
- subject: Add a `throughTarStream` helper that can be used without buffering memory
|
|
88
|
-
hash: 71097226c3a1672ca453f7d61201aa7833052930
|
|
89
|
-
body: ""
|
|
90
|
-
footer:
|
|
91
|
-
Change-type: minor
|
|
92
|
-
change-type: minor
|
|
93
|
-
author: Pagan Gazzard
|
|
94
|
-
version: 3.1.0
|
|
95
|
-
title: ""
|
|
96
|
-
date: 2025-09-24T15:48:15.342Z
|
|
97
|
-
- commits:
|
|
98
|
-
- subject: "`cloneTarStream`: stream entries directly to the pack where possible"
|
|
99
|
-
hash: 7317113a6000351683eacddcc39582e876e0adc5
|
|
100
|
-
body: ""
|
|
101
|
-
footer:
|
|
102
|
-
Change-type: patch
|
|
103
|
-
change-type: patch
|
|
104
|
-
author: Pagan Gazzard
|
|
105
|
-
version: 3.0.5
|
|
106
|
-
title: ""
|
|
107
|
-
date: 2025-09-24T13:38:04.396Z
|
|
108
|
-
- commits:
|
|
109
|
-
- subject: Update dev dependencies
|
|
110
|
-
hash: 4d67b1857344799c98500585f55c55e5e8078182
|
|
111
|
-
body: ""
|
|
112
|
-
footer:
|
|
113
|
-
Change-type: patch
|
|
114
|
-
change-type: patch
|
|
115
|
-
author: Pagan Gazzard
|
|
116
|
-
version: 3.0.4
|
|
117
|
-
title: ""
|
|
118
|
-
date: 2025-09-24T13:12:44.510Z
|
|
119
|
-
- commits:
|
|
120
|
-
- subject: "tests: Remove no longer used Bluebird import"
|
|
121
|
-
hash: 3d767b6fc7c6cc4781cd07aeaa287b578d93fa40
|
|
122
|
-
body: ""
|
|
123
|
-
footer:
|
|
124
|
-
Change-type: patch
|
|
125
|
-
change-type: patch
|
|
126
|
-
author: Thodoris Greasidis
|
|
127
|
-
version: 3.0.3
|
|
128
|
-
title: ""
|
|
129
|
-
date: 2025-09-19T12:40:58.145Z
|
|
130
|
-
- commits:
|
|
131
|
-
- subject: Update to tar-stream 3.1.6
|
|
132
|
-
hash: 082499aeab9048414869b0d6d8960b7913a11dbb
|
|
133
|
-
body: ""
|
|
134
|
-
footer:
|
|
135
|
-
Change-type: patch
|
|
136
|
-
change-type: patch
|
|
137
|
-
author: Pagan Gazzard
|
|
138
|
-
version: 3.0.2
|
|
139
|
-
title: ""
|
|
140
|
-
date: 2023-07-05T15:51:44.966Z
|
|
141
|
-
- commits:
|
|
142
|
-
- subject: Fix `cloneTarStream` when passing `onEntry` option
|
|
143
|
-
hash: 59cbcd1f9b51fd05619abfa3887d94417e431ba1
|
|
144
|
-
body: ""
|
|
145
|
-
footer:
|
|
146
|
-
Change-type: patch
|
|
147
|
-
change-type: patch
|
|
148
|
-
author: Pagan Gazzard
|
|
149
|
-
version: 3.0.1
|
|
150
|
-
title: ""
|
|
151
|
-
date: 2023-07-05T15:24:10.325Z
|
|
152
|
-
- commits:
|
|
153
|
-
- subject: Update tar-stream to 3.x
|
|
154
|
-
hash: f4e87ea24df2acb73d1227049835b992d03e0778
|
|
155
|
-
body: ""
|
|
156
|
-
footer:
|
|
157
|
-
Change-type: major
|
|
158
|
-
change-type: major
|
|
159
|
-
author: Pagan Gazzard
|
|
160
|
-
- subject: Switch from bluebird to native promises
|
|
161
|
-
hash: 2a5f004a5319550c5070453207f00ea20f3fc4c3
|
|
162
|
-
body: ""
|
|
163
|
-
footer:
|
|
164
|
-
Change-type: major
|
|
165
|
-
change-type: major
|
|
166
|
-
author: Pagan Gazzard
|
|
167
|
-
- subject: Update minimum nodejs version to 16.13.0
|
|
168
|
-
hash: 6c589624a856cd99bd3d8c2c6c81803f9592a948
|
|
169
|
-
body: ""
|
|
170
|
-
footer:
|
|
171
|
-
Change-type: major
|
|
172
|
-
change-type: major
|
|
173
|
-
author: Pagan Gazzard
|
|
174
|
-
version: 3.0.0
|
|
175
|
-
title: ""
|
|
176
|
-
date: 2023-07-05T13:10:36.915Z
|
|
177
|
-
- commits:
|
|
178
|
-
- subject: Add .version/CHANGELOG.yml for nested changelogs
|
|
179
|
-
hash: ad1f96a9114c7135870939710f100fd2ef6ba154
|
|
180
|
-
body: ""
|
|
181
|
-
footer:
|
|
182
|
-
Change-type: patch
|
|
183
|
-
change-type: patch
|
|
184
|
-
author: Pagan Gazzard
|
|
185
|
-
version: 2.1.3
|
|
186
|
-
date: 2020-08-20T18:01:29.420Z
|
|
187
|
-
- commits:
|
|
188
|
-
- author: Pagan Gazzard
|
|
189
|
-
body: ""
|
|
190
|
-
footers:
|
|
191
|
-
change-type: patch
|
|
192
|
-
hash: 7f66c68e735a9779aadb9b04891d3022ce4e6dc7
|
|
193
|
-
subject: Explicitly disable backpressure in `cloneTarStream` to buffer in memory
|
|
194
|
-
- author: Pagan Gazzard
|
|
195
|
-
body: ""
|
|
196
|
-
footers:
|
|
197
|
-
change-type: patch
|
|
198
|
-
hash: 3c49d50c543300733fb5e2e2324251f855e87b19
|
|
199
|
-
subject: Remove lodash dependency
|
|
200
|
-
- author: Pagan Gazzard
|
|
201
|
-
body: ""
|
|
202
|
-
hash: 7c840b80fce0bbd1f7dfdd415bf7b1acf1ab312a
|
|
203
|
-
subject: Switch to @balena/lint
|
|
204
|
-
date: 2020-08-14T11:31:15Z
|
|
205
|
-
version: 2.1.2
|
|
206
|
-
- commits:
|
|
207
|
-
- author: Paulo Castro
|
|
208
|
-
body: ""
|
|
209
|
-
footers:
|
|
210
|
-
change-type: patch
|
|
211
|
-
hash: 46e9b0a6714e3017b1b14fd2fdfccb38eee9e551
|
|
212
|
-
subject: Fix documentation for normalizeTarEntry
|
|
213
|
-
- author: Paulo Castro
|
|
214
|
-
body: ""
|
|
215
|
-
footers:
|
|
216
|
-
change-type: patch
|
|
217
|
-
hash: 74c7d9e9231aa41c160355528856a8dd7106723f
|
|
218
|
-
subject: Update gulp for Node v12, and update gulpfile for gulp v4
|
|
219
|
-
- author: Paulo Castro
|
|
220
|
-
body: ""
|
|
221
|
-
footers:
|
|
222
|
-
change-type: patch
|
|
223
|
-
hash: 31ff953aadf3a8d5f51922d93c7c416cf39d403c
|
|
224
|
-
subject: Pin tar-stream to v2.1.1 to avoid a sudden silent process crash
|
|
225
|
-
date: 2020-08-13T21:59:34Z
|
|
226
|
-
version: 2.1.1
|
|
227
|
-
- commits:
|
|
228
|
-
- author: Pagan Gazzard
|
|
229
|
-
body: ""
|
|
230
|
-
footers:
|
|
231
|
-
change-type: minor
|
|
232
|
-
hash: 05d16cba3ac6cc603c33b9ce67dde95a4d5291c0
|
|
233
|
-
subject: Update dependencies and use declaration files for types
|
|
234
|
-
date: 2020-03-04T12:16:22Z
|
|
235
|
-
version: 2.1.0
|
|
236
|
-
- commits:
|
|
237
|
-
- author: Paulo Castro
|
|
238
|
-
body: |-
|
|
239
|
-
normalizeTarEntry() now also removes trailing slashes, reason why
|
|
240
|
-
the change-type is major.
|
|
241
|
-
footers:
|
|
242
|
-
change-type: major
|
|
243
|
-
connects-to: https://github.com/balena-io/balena-cli/issues/1133
|
|
244
|
-
signed-off-by: Paulo Castro <paulo@balena.io>
|
|
245
|
-
hash: 7aaa90613a6a457d57a7edd64ff5101f39a2c73f
|
|
246
|
-
subject: Fix path separator used by normalizeTarEntry() under Windows.
|
|
247
|
-
date: 2019-04-16T12:31:27Z
|
|
248
|
-
version: 2.0.0
|
|
249
|
-
- commits:
|
|
250
|
-
- author: Paulo Castro
|
|
251
|
-
body: ""
|
|
252
|
-
footers:
|
|
253
|
-
change-type: minor
|
|
254
|
-
signed-off-by: Paulo Castro <paulo@balena.io>
|
|
255
|
-
hash: 01835dda5bc3ea7388f64d2a739b704624c2f6a5
|
|
256
|
-
subject: Added pipePromise, cloneTarStream and multicastStream functions
|
|
257
|
-
date: 2019-02-18T16:15:09Z
|
|
258
|
-
version: 1.1.0
|
|
259
|
-
- commits:
|
|
260
|
-
- author: Pagan Gazzard
|
|
261
|
-
body: ""
|
|
262
|
-
footers:
|
|
263
|
-
change-type: patch
|
|
264
|
-
hash: 3783e6c9ce63225a4ca4c9a8c1b9693d72f0ed76
|
|
265
|
-
subject: Only concat buffers once at the end, reducing the amount of copying and
|
|
266
|
-
garbage collection massively.
|
|
267
|
-
date: 2018-07-17T18:18:19Z
|
|
268
|
-
version: 1.0.6
|
|
269
|
-
- commits:
|
|
270
|
-
- author: Pagan Gazzard
|
|
271
|
-
body: ""
|
|
272
|
-
footers:
|
|
273
|
-
change-type: patch
|
|
274
|
-
hash: e88cf7626cc59b50b585e96f33575d7f5d0e4296
|
|
275
|
-
subject: Fixes for use on windows
|
|
276
|
-
date: 2018-07-17T18:05:14Z
|
|
277
|
-
version: 1.0.5
|
|
278
|
-
- commits:
|
|
279
|
-
- author: Pagan Gazzard
|
|
280
|
-
body: ""
|
|
281
|
-
footers:
|
|
282
|
-
change-type: patch
|
|
283
|
-
hash: a8f8a9d004874dd30731e4cd7a2545d68ed10e7f
|
|
284
|
-
subject: Ignore node_modules
|
|
285
|
-
date: 2018-07-17T17:50:09Z
|
|
286
|
-
version: 1.0.4
|
|
287
|
-
- commits:
|
|
288
|
-
- author: Pagan Gazzard
|
|
289
|
-
body: ""
|
|
290
|
-
hash: 7ea0c561b3917db05a60329910c681730c723f69
|
|
291
|
-
subject: Add versionist
|
|
292
|
-
- author: Pagan Gazzard
|
|
293
|
-
body: ""
|
|
294
|
-
footers:
|
|
295
|
-
change-type: patch
|
|
296
|
-
hash: 54c75df4473384fae89ba0a6cd42fcf820470436
|
|
297
|
-
subject: Enable circleci testing and auto-publishing.
|
|
298
|
-
date: 2018-07-17T17:39:15Z
|
|
299
|
-
version: 1.0.3
|
|
300
|
-
- commits:
|
|
301
|
-
- author: Cameron Diver
|
|
302
|
-
body: ""
|
|
303
|
-
footers:
|
|
304
|
-
change-type: patch
|
|
305
|
-
signed-off-by: Cameron Diver <cameron@resin.io>
|
|
306
|
-
hash: 9d0c4d93d76a9458af4c479d7455c5f287699cdb
|
|
307
|
-
subject: Update dependencies and clean up project
|
|
308
|
-
date: 2017-12-04T12:10:16Z
|
|
309
|
-
version: 1.0.2
|
|
Binary file
|
package/tests/tests.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2019 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
|
-
import { expect } from 'chai';
|
|
18
|
-
import { PassThrough, Readable, Writable } from 'stream';
|
|
19
|
-
|
|
20
|
-
import * as fs from 'fs';
|
|
21
|
-
import * as tar from 'tar-stream';
|
|
22
|
-
|
|
23
|
-
import * as TarUtils from '../lib';
|
|
24
|
-
|
|
25
|
-
describe('Simple utils', () => {
|
|
26
|
-
it('should correctly normalize a tar entry', () => {
|
|
27
|
-
const testCases = [
|
|
28
|
-
// input, expected output
|
|
29
|
-
// a slash is also programmatically appended to every input test case
|
|
30
|
-
['', ''],
|
|
31
|
-
['.', '.'],
|
|
32
|
-
['..', '..'],
|
|
33
|
-
['/', '.'],
|
|
34
|
-
['/.', '.'],
|
|
35
|
-
['/..', '.'], // root's parent? hmm
|
|
36
|
-
['Dockerfile', 'Dockerfile'],
|
|
37
|
-
['./Dockerfile', 'Dockerfile'],
|
|
38
|
-
['../Dockerfile', `../Dockerfile`],
|
|
39
|
-
['/Dockerfile', 'Dockerfile'],
|
|
40
|
-
['./a/b/Dockerfile', `a/b/Dockerfile`],
|
|
41
|
-
['./a/../b/Dockerfile', `b/Dockerfile`],
|
|
42
|
-
['///a//b/Dockerfile', `a/b/Dockerfile`],
|
|
43
|
-
['a/./b/Dockerfile', `a/b/Dockerfile`],
|
|
44
|
-
];
|
|
45
|
-
for (let [input, expected] of testCases) {
|
|
46
|
-
let result = TarUtils.normalizeTarEntry(input);
|
|
47
|
-
expect(result).to.equal(
|
|
48
|
-
expected,
|
|
49
|
-
`normalizeTarEntry('${input}') returned '${result}', expected '${expected}'`,
|
|
50
|
-
);
|
|
51
|
-
if (input === '') {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
// adding a trailing slash to the input should not alter the output
|
|
55
|
-
input += '/';
|
|
56
|
-
result = TarUtils.normalizeTarEntry(input);
|
|
57
|
-
expect(result).to.equal(
|
|
58
|
-
expected,
|
|
59
|
-
`normalizeTarEntry('${input}') returned '${result}' expected '${expected}'`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should read a stream to a buffer', async () => {
|
|
65
|
-
const readable = new PassThrough();
|
|
66
|
-
|
|
67
|
-
readable.write('test-string');
|
|
68
|
-
readable.end();
|
|
69
|
-
|
|
70
|
-
const buf = await TarUtils.streamToBuffer(readable);
|
|
71
|
-
expect(buf.toString()).to.equal('test-string');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('pipeStream', function () {
|
|
76
|
-
const hwm = 16333; // high water mark
|
|
77
|
-
const sourceBuf = Buffer.alloc(71000, '0123456789');
|
|
78
|
-
|
|
79
|
-
it('should resolve when the pipe operation completes', async () => {
|
|
80
|
-
const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf);
|
|
81
|
-
const toStream = new MockWritable({ highWaterMark: hwm });
|
|
82
|
-
|
|
83
|
-
await TarUtils.pipePromise(fromStream, toStream);
|
|
84
|
-
const destBuf = Buffer.concat(toStream.chunks);
|
|
85
|
-
expect(sourceBuf.compare(destBuf)).to.equal(0);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('cloneTarStream', function () {
|
|
90
|
-
const hwm = 16333; // high water mark
|
|
91
|
-
|
|
92
|
-
it('should successfully clone a tar file', async () => {
|
|
93
|
-
const sourceTarStream = fs.createReadStream(
|
|
94
|
-
'./tests/test-files/cloneTarStream.tar',
|
|
95
|
-
{
|
|
96
|
-
highWaterMark: hwm,
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
const expectedEntries = [
|
|
100
|
-
['./', 0],
|
|
101
|
-
['./fileSize150K.png', 150524],
|
|
102
|
-
['./fileSizeTen.txt', 10],
|
|
103
|
-
['./fileSizeZero', 0],
|
|
104
|
-
['./aFolder/', 0],
|
|
105
|
-
['./aFolder/fileSizeTen.txt', 10],
|
|
106
|
-
['./aFolder/fileSizeZero', 0],
|
|
107
|
-
];
|
|
108
|
-
|
|
109
|
-
const pack = await TarUtils.cloneTarStream(sourceTarStream);
|
|
110
|
-
await new Promise<void>((resolve, reject) => {
|
|
111
|
-
let i = 0;
|
|
112
|
-
const extract = tar.extract();
|
|
113
|
-
pack.on('error', reject);
|
|
114
|
-
extract.on('error', reject);
|
|
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
|
-
});
|
|
130
|
-
pack.pipe(extract);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('multicastStream', function () {
|
|
136
|
-
this.timeout(60000);
|
|
137
|
-
const sourceBuf = Buffer.alloc(71011, '0123456789');
|
|
138
|
-
const hwm = 16384; // high water mark
|
|
139
|
-
|
|
140
|
-
it('should successfully multicast a producer stream to different-pace consumers', async () => {
|
|
141
|
-
const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf);
|
|
142
|
-
const toStreams: MockWritable[] = [];
|
|
143
|
-
const nStreams = 3;
|
|
144
|
-
for (let i = 0; i < nStreams; ++i) {
|
|
145
|
-
toStreams.push(
|
|
146
|
-
new MockWritable({ highWaterMark: Math.ceil(hwm / (i + 1)) }, i * 10),
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
await TarUtils.multicastStream(fromStream, toStreams);
|
|
151
|
-
for (const toStream of toStreams) {
|
|
152
|
-
const dest = Buffer.concat(toStream.chunks);
|
|
153
|
-
expect(toStream.chunks.length).to.equal(
|
|
154
|
-
Math.ceil(sourceBuf.length / hwm),
|
|
155
|
-
);
|
|
156
|
-
expect(sourceBuf.compare(dest)).to.equal(0);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should resolve for an empty list of destination streams', async () => {
|
|
161
|
-
const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf);
|
|
162
|
-
await TarUtils.multicastStream(fromStream, []);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should reject when a destination stream emits an error', async () => {
|
|
166
|
-
const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf);
|
|
167
|
-
const toStreams: MockWritable[] = [];
|
|
168
|
-
const nStreams = 3;
|
|
169
|
-
for (let i = 0; i < nStreams; ++i) {
|
|
170
|
-
toStreams.push(new MockWritable({ highWaterMark: hwm }, 0, i + 1));
|
|
171
|
-
}
|
|
172
|
-
try {
|
|
173
|
-
await TarUtils.multicastStream(fromStream, toStreams);
|
|
174
|
-
throw new Error(
|
|
175
|
-
'multicastStream call should have rejected, but succeeded',
|
|
176
|
-
);
|
|
177
|
-
} catch (error) {
|
|
178
|
-
expect(error.message).to.equal('write count is 1');
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('should reject when the source stream emits an error', async () => {
|
|
183
|
-
const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf, 2);
|
|
184
|
-
const toStreams: MockWritable[] = [];
|
|
185
|
-
const nStreams = 3;
|
|
186
|
-
for (let i = 0; i < nStreams; ++i) {
|
|
187
|
-
toStreams.push(new MockWritable({ highWaterMark: hwm }, 0));
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
await TarUtils.multicastStream(fromStream, toStreams);
|
|
191
|
-
throw new Error(
|
|
192
|
-
'multicastStream call should have rejected, but succeeded',
|
|
193
|
-
);
|
|
194
|
-
} catch (error) {
|
|
195
|
-
expect(error.message).to.equal('read count is 2');
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
class MockReadable extends Readable {
|
|
201
|
-
public readCount = 0;
|
|
202
|
-
public index = 0;
|
|
203
|
-
|
|
204
|
-
constructor(
|
|
205
|
-
opts: object,
|
|
206
|
-
public sourceBuf: Buffer,
|
|
207
|
-
public errorOnCount = -1,
|
|
208
|
-
) {
|
|
209
|
-
super(opts);
|
|
210
|
-
}
|
|
211
|
-
public _read(size: number) {
|
|
212
|
-
if (this.readCount++ === this.errorOnCount) {
|
|
213
|
-
this.emit('error', new Error(`read count is ${this.errorOnCount}`));
|
|
214
|
-
} else {
|
|
215
|
-
let pushOK = true;
|
|
216
|
-
while (pushOK) {
|
|
217
|
-
if (this.index >= this.sourceBuf.length) {
|
|
218
|
-
this.push(null);
|
|
219
|
-
break;
|
|
220
|
-
} else {
|
|
221
|
-
pushOK = this.push(
|
|
222
|
-
this.sourceBuf.slice(this.index, this.index + size),
|
|
223
|
-
);
|
|
224
|
-
this.index += size;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
class MockWritable extends Writable {
|
|
232
|
-
public writeCount = 0;
|
|
233
|
-
public chunks: Buffer[] = [];
|
|
234
|
-
|
|
235
|
-
constructor(
|
|
236
|
-
opts: object,
|
|
237
|
-
public delay = 0,
|
|
238
|
-
public errorOnCount = -1,
|
|
239
|
-
) {
|
|
240
|
-
super(opts);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
public _write(
|
|
244
|
-
chunk: Buffer,
|
|
245
|
-
_encoding: any,
|
|
246
|
-
callback: (error: Error | null) => void,
|
|
247
|
-
) {
|
|
248
|
-
let error: Error | null;
|
|
249
|
-
if (this.writeCount++ === this.errorOnCount) {
|
|
250
|
-
error = new Error(`write count is ${this.errorOnCount}`);
|
|
251
|
-
} else {
|
|
252
|
-
this.chunks.push(chunk);
|
|
253
|
-
error = null;
|
|
254
|
-
}
|
|
255
|
-
if (this.delay < 1) {
|
|
256
|
-
process.nextTick(callback, error);
|
|
257
|
-
} else {
|
|
258
|
-
setTimeout(callback, this.delay, error);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
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
|
-
}
|
package/tsconfig.dev.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"target": "es2021",
|
|
5
|
-
"outDir": "build",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"noImplicitAny": true,
|
|
8
|
-
"noUnusedLocals": true,
|
|
9
|
-
"noUnusedParameters": true,
|
|
10
|
-
"strictNullChecks": true,
|
|
11
|
-
"preserveConstEnums": true,
|
|
12
|
-
"pretty": true,
|
|
13
|
-
"removeComments": true,
|
|
14
|
-
"sourceMap": true,
|
|
15
|
-
"skipLibCheck": true
|
|
16
|
-
},
|
|
17
|
-
"include": [
|
|
18
|
-
"lib/**/*.ts"
|
|
19
|
-
],
|
|
20
|
-
"exclude": [
|
|
21
|
-
"node_modules"
|
|
22
|
-
]
|
|
23
|
-
}
|