Skip to content

Commit 5c1113b

Browse files
committed
s/onentry/onReadEntry/g for clarity, deprecate old name
1 parent 556a13c commit 5c1113b

File tree

13 files changed

+86
-63
lines changed

13 files changed

+86
-63
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 7.4
4+
5+
- Deprecate `onentry` in favor of `onReadEntry` for clarity.
6+
7+
## 7.3
8+
9+
- Add `onWriteEntry` option
10+
311
## 7.2
412

513
- DRY the command definitions into a single `makeCommand` method,

README.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ To replicate `tar tf my-tarball.tgz`, do this:
214214
```js
215215
tar.t({
216216
file: 'my-tarball.tgz',
217-
onentry: entry => { .. do whatever with it .. }
217+
onReadEntry: entry => { .. do whatever with it .. }
218218
})
219219
```
220220

@@ -225,7 +225,7 @@ const getEntryFilenames = async tarballFilename => {
225225
const filenames = []
226226
await tar.t({
227227
file: tarballFilename,
228-
onentry: entry => filenames.push(entry.path),
228+
onReadEntry: entry => filenames.push(entry.path),
229229
})
230230
return filenames
231231
}
@@ -250,7 +250,7 @@ const getEntryFilenamesSync = tarballFilename => {
250250
const filenames = []
251251
tar.t({
252252
file: tarballFilename,
253-
onentry: entry => filenames.push(entry.path),
253+
onReadEntry: entry => filenames.push(entry.path),
254254
sync: true,
255255
})
256256
return filenames
@@ -335,6 +335,9 @@ The following options are supported:
335335
[Alias: `m`, `no-mtime`]
336336
- `mtime` Set to a `Date` object to force a specific `mtime` for
337337
everything added to the archive. Overridden by `noMtime`.
338+
- `onWriteEntry` Called with each `WriteEntry` or
339+
`WriteEntrySync` that is created in the course of writing the
340+
archive.
338341

339342
The following options are mostly internal, but can be modified in some
340343
advanced use cases, such as re-using caches between runs.
@@ -427,7 +430,7 @@ The following options are supported:
427430
the archive entry. If a falsey value is provided, then the entry is
428431
written to disk as normal. (To exclude items from extraction, use
429432
the `filter` option described above.)
430-
- `onentry` A function that gets called with `(entry)` for each entry
433+
- `onReadEntry` A function that gets called with `(entry)` for each entry
431434
that passes the filter.
432435
- `onwarn` A function that will get called with `(code, message, data)` for
433436
any warnings encountered. (See "Warnings and Errors")
@@ -478,7 +481,7 @@ entries, use the `tar.Parse` class instead.)
478481

479482
If a `file` option _is_ provided, then the return value will be a promise
480483
that resolves when the file has been fully traversed in async mode, or
481-
`undefined` if `sync: true` is set. Thus, you _must_ specify an `onentry`
484+
`undefined` if `sync: true` is set. Thus, you _must_ specify an `onReadEntry`
482485
method in order to do anything useful with the data it parses.
483486

484487
The following options are supported:
@@ -493,13 +496,13 @@ The following options are supported:
493496
- `filter` A function that gets called with `(path, entry)` for each
494497
entry being listed. Return `true` to emit the entry from the
495498
archive, or `false` to skip it.
496-
- `onentry` A function that gets called with `(entry)` for each entry
499+
- `onReadEntry` A function that gets called with `(entry)` for each entry
497500
that passes the filter. This is important for when `file` is set,
498501
because there is no other way to do anything useful with this method.
499502
- `maxReadSize` The maximum buffer size for `fs.read()` operations.
500503
Defaults to 16 MB.
501504
- `noResume` By default, `entry` streams are resumed immediately after
502-
the call to `onentry`. Set `noResume: true` to suppress this
505+
the call to `onReadEntry`. Set `noResume: true` to suppress this
503506
behavior. Note that by opting into this, the stream will never
504507
complete until the entry data is consumed.
505508
- `onwarn` A function that will get called with `(code, message, data)` for
@@ -556,6 +559,9 @@ The following options are supported:
556559
[Alias: `m`, `no-mtime`]
557560
- `mtime` Set to a `Date` object to force a specific `mtime` for
558561
everything added to the archive. Overridden by `noMtime`.
562+
- `onWriteEntry` Called with each `WriteEntry` or
563+
`WriteEntrySync` that is created in the course of writing the
564+
archive.
559565

560566
### tar.r(options, fileList, callback) [alias: tar.replace]
561567

@@ -608,10 +614,13 @@ The following options are supported:
608614
[Alias: `m`, `no-mtime`]
609615
- `mtime` Set to a `Date` object to force a specific `mtime` for
610616
everything added to the archive. Overridden by `noMtime`.
617+
- `onWriteEntry` Called with each `WriteEntry` or
618+
`WriteEntrySync` that is created in the course of writing the
619+
archive.
611620

612621
## Low-Level API
613622

614-
### class tar.Pack
623+
### class Pack
615624

616625
A readable tar stream.
617626

@@ -640,7 +649,6 @@ The following options are supported:
640649
default" for most unix systems, based on a `umask` value of `0o22`.
641650
- `preservePaths` Allow absolute paths. By default, `/` is stripped
642651
from absolute paths.
643-
644652
- `linkCache` A Map object containing the device and inode value for
645653
any file whose nlink is > 1, to identify hard links.
646654
- `statCache` A Map object that caches calls `lstat`.
@@ -661,6 +669,9 @@ The following options are supported:
661669
`tar.update` or the `keepNewer` option with the resulting tar archive.
662670
- `mtime` Set to a `Date` object to force a specific `mtime` for
663671
everything added to the archive. Overridden by `noMtime`.
672+
- `onWriteEntry` Called with each `WriteEntry` or
673+
`WriteEntrySync` that is created in the course of writing the
674+
archive.
664675

665676
#### add(path)
666677

@@ -674,11 +685,11 @@ Adds an entry to the archive. Returns true if flushed.
674685

675686
Finishes the archive.
676687

677-
### class tar.Pack.Sync
688+
### class PackSync
678689

679-
Synchronous version of `tar.Pack`.
690+
Synchronous version of `Pack`.
680691

681-
### class tar.Unpack
692+
### class Unpack
682693

683694
A writable stream that unpacks a tar archive onto the file system.
684695

@@ -757,7 +768,7 @@ Most unpack errors will cause a `warn` event to be emitted. If the
757768
written to disk as normal. (To exclude items from extraction, use
758769
the `filter` option described above.)
759770
- `strict` Treat warnings as crash-worthy errors. Default false.
760-
- `onentry` A function that gets called with `(entry)` for each entry
771+
- `onReadEntry` A function that gets called with `(entry)` for each entry
761772
that passes the filter.
762773
- `onwarn` A function that will get called with `(code, message, data)` for
763774
any warnings encountered. (See "Warnings and Errors")
@@ -775,9 +786,9 @@ Most unpack errors will cause a `warn` event to be emitted. If the
775786
warning and skip the entry. Set to `Infinity` to remove the
776787
limitation.
777788

778-
### class tar.Unpack.Sync
789+
### class UnpackSync
779790

780-
Synchronous version of `tar.Unpack`.
791+
Synchronous version of `Unpack`.
781792

782793
Note that using an asynchronous stream type with the `transform`
783794
option will cause undefined behavior in sync unpack streams.
@@ -810,7 +821,7 @@ The following options are supported:
810821
- `filter` A function that gets called with `(path, entry)` for each
811822
entry being listed. Return `true` to emit the entry from the
812823
archive, or `false` to skip it.
813-
- `onentry` A function that gets called with `(entry)` for each entry
824+
- `onReadEntry` A function that gets called with `(entry)` for each entry
814825
that passes the filter.
815826
- `onwarn` A function that will get called with `(code, message, data)` for
816827
any warnings encountered. (See "Warnings and Errors")

src/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const addFilesSync = (p: PackSync, files: string[]) => {
4545
file: path.resolve(p.cwd, file.slice(1)),
4646
sync: true,
4747
noResume: true,
48-
onentry: entry => p.add(entry),
48+
onReadEntry: entry => p.add(entry),
4949
})
5050
} else {
5151
p.add(file)
@@ -64,7 +64,7 @@ const addFilesAsync = async (
6464
await list({
6565
file: path.resolve(String(p.cwd), file.slice(1)),
6666
noResume: true,
67-
onentry: entry => {
67+
onReadEntry: entry => {
6868
p.add(entry)
6969
},
7070
})

src/list.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import {
1111
import { Parser } from './parse.js'
1212
import { stripTrailingSlashes } from './strip-trailing-slashes.js'
1313

14-
const onentryFunction = (opt: TarOptions) => {
15-
const onentry = opt.onentry
16-
opt.onentry =
17-
onentry ?
14+
const onReadEntryFunction = (opt: TarOptions) => {
15+
const onReadEntry = opt.onReadEntry
16+
opt.onReadEntry =
17+
onReadEntry ?
1818
e => {
19-
onentry(e)
19+
onReadEntry(e)
2020
e.resume()
2121
}
2222
: e => e.resume()
@@ -119,6 +119,6 @@ export const list = makeCommand(
119119
opt => new Parser(opt),
120120
(opt, files) => {
121121
if (files?.length) filesFilter(opt, files)
122-
if (!opt.noResume) onentryFunction(opt)
122+
if (!opt.noResume) onReadEntryFunction(opt)
123123
},
124124
)

src/options.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const argmap = new Map<keyof TarOptionsWithAliases, keyof TarOptions>(
2727
['p', 'preserveOwner'],
2828
['L', 'follow'],
2929
['h', 'follow'],
30+
['onentry', 'onReadEntry'],
3031
],
3132
)
3233

@@ -265,7 +266,7 @@ export interface TarOptions {
265266

266267
/**
267268
* When parsing/listing archives, `entry` streams are by default resumed
268-
* (set into "flowing" mode) immediately after the call to `onentry()`.
269+
* (set into "flowing" mode) immediately after the call to `onReadEntry()`.
269270
* Set `noResume: true` to suppress this behavior.
270271
*
271272
* Note that when this is set, the stream will never complete until the
@@ -279,10 +280,6 @@ export interface TarOptions {
279280
/**
280281
* When creating, updating, or replacing within archives, this method will
281282
* be called with each WriteEntry that is created.
282-
*
283-
* It's not called 'onentry' because that's already taken for the ReadEntry
284-
* when reading archives, and it's just easier to only have one type of
285-
* options object that this whole library can pass around without issue.
286283
*/
287284
onWriteEntry?: (entry: WriteEntry) => any
288285

@@ -293,7 +290,7 @@ export interface TarOptions {
293290
* Important when listing archives synchronously from a file, because there
294291
* is otherwise no way to interact with the data!
295292
*/
296-
onentry?: (entry: ReadEntry) => any
293+
onReadEntry?: (entry: ReadEntry) => any
297294

298295
/**
299296
* Pack the targets of symbolic links rather than the link itself.
@@ -477,6 +474,13 @@ export interface TarOptions {
477474
* Forcibly trigger a chown on every entry, no matter what.
478475
*/
479476
forceChown?: boolean
477+
478+
/**
479+
* ambiguous deprecated name for {@link onReadEntry}
480+
*
481+
* @deprecated
482+
*/
483+
onentry?: (entry: ReadEntry) => any
480484
}
481485

482486
export type TarOptionsSync = TarOptions & { sync: true }

src/parse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export class Parser extends EE implements Warner {
147147
if (typeof opt.onwarn === 'function') {
148148
this.on('warn', opt.onwarn)
149149
}
150-
if (typeof opt.onentry === 'function') {
151-
this.on('entry', opt.onentry)
150+
if (typeof opt.onReadEntry === 'function') {
151+
this.on('entry', opt.onReadEntry)
152152
}
153153
}
154154

src/replace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ const addFilesSync = (p: Pack, files: string[]) => {
239239
file: path.resolve(p.cwd, file.slice(1)),
240240
sync: true,
241241
noResume: true,
242-
onentry: entry => p.add(entry),
242+
onReadEntry: entry => p.add(entry),
243243
})
244244
} else {
245245
p.add(file)
@@ -258,7 +258,7 @@ const addFilesAsync = async (
258258
await list({
259259
file: path.resolve(String(p.cwd), file.slice(1)),
260260
noResume: true,
261-
onentry: entry => p.add(entry),
261+
onReadEntry: entry => p.add(entry),
262262
})
263263
} else {
264264
p.add(file)

test/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ t.test('create tarball out of another tarball', t => {
241241
list({
242242
f: out,
243243
sync: true,
244-
onentry: entry => {
244+
onReadEntry: entry => {
245245
if (entry.path === 'hardlink-2') {
246246
t.equal(entry.type, 'Link')
247247
} else if (entry.path === 'symlink') {

0 commit comments

Comments
 (0)