Skip to content

Commit 0fbeaed

Browse files
committed
formatting
1 parent 2dbacfe commit 0fbeaed

File tree

12 files changed

+106
-85
lines changed

12 files changed

+106
-85
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# keep these
77
!**/.gitignore
8+
!/.prettierignore
89
!/src
910
!/.tshy
1011
!/.commitlintrc.js

.prettierignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/node_modules
2+
/LICENSE.md
3+
/example
4+
/.github
5+
/dist
6+
/.env
7+
/tap-snapshots
8+
/.nyc_output
9+
/coverage
10+
/benchmark
11+
/.tap
12+
/test/fixture
13+
/test/fixtures
14+
/.tshy

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ Handlers receive 3 arguments:
103103

104104
- `TAR_ENTRY_INVALID` An indication that a given entry is not a valid tar
105105
archive entry, and will be skipped. This occurs when:
106-
107106
- a checksum fails,
108107
- a `linkpath` is missing for a link type, or
109108
- a `linkpath` is provided for a non-link type.
@@ -115,7 +114,6 @@ Handlers receive 3 arguments:
115114
- `TAR_ENTRY_ERROR` The entry appears to be a valid tar archive entry, but
116115
encountered an error which prevented it from being unpacked. This occurs
117116
when:
118-
119117
- an unrecoverable fs error happens during unpacking,
120118
- an entry is trying to extract into an excessively deep
121119
location (by default, limited to 1024 subfolders),
@@ -133,7 +131,6 @@ Handlers receive 3 arguments:
133131

134132
- `TAR_BAD_ARCHIVE` The archive file is totally hosed. This can happen for
135133
a number of reasons, and always occurs at the end of a parse or extract:
136-
137134
- An entry body was truncated before seeing the full number of bytes.
138135
- The archive contained only invalid entries, indicating that it is
139136
likely not an archive, or at least, not an archive this library can

src/header.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export class Header implements HeaderData {
9191
this.uid = ex?.uid ?? gex?.uid ?? decNumber(buf, off + 108, 8)
9292
this.gid = ex?.gid ?? gex?.gid ?? decNumber(buf, off + 116, 8)
9393
this.size = ex?.size ?? gex?.size ?? decNumber(buf, off + 124, 12)
94-
this.mtime = ex?.mtime ?? gex?.mtime ?? decDate(buf, off + 136, 12)
94+
this.mtime =
95+
ex?.mtime ?? gex?.mtime ?? decDate(buf, off + 136, 12)
9596
this.cksum = decNumber(buf, off + 148, 12)
9697

9798
// if we have extended or global extended headers, apply them now
@@ -124,10 +125,14 @@ export class Header implements HeaderData {
124125
'ustar\u000000'
125126
) {
126127
/* c8 ignore start */
127-
this.uname = ex?.uname ?? gex?.uname ?? decString(buf, off + 265, 32)
128-
this.gname = ex?.gname ?? gex?.gname ?? decString(buf, off + 297, 32)
129-
this.devmaj = ex?.devmaj ?? gex?.devmaj ?? decNumber(buf, off + 329, 8) ?? 0
130-
this.devmin = ex?.devmin ?? gex?.devmin ?? decNumber(buf, off + 337, 8) ?? 0
128+
this.uname =
129+
ex?.uname ?? gex?.uname ?? decString(buf, off + 265, 32)
130+
this.gname =
131+
ex?.gname ?? gex?.gname ?? decString(buf, off + 297, 32)
132+
this.devmaj =
133+
ex?.devmaj ?? gex?.devmaj ?? decNumber(buf, off + 329, 8) ?? 0
134+
this.devmin =
135+
ex?.devmin ?? gex?.devmin ?? decNumber(buf, off + 337, 8) ?? 0
131136
/* c8 ignore stop */
132137
if (buf[off + 475] !== 0) {
133138
// definitely a prefix, definitely >130 chars.
@@ -139,8 +144,10 @@ export class Header implements HeaderData {
139144
this.path = prefix + '/' + this.path
140145
}
141146
/* c8 ignore start */
142-
this.atime = ex?.atime ?? gex?.atime ?? decDate(buf, off + 476, 12)
143-
this.ctime = ex?.ctime ?? gex?.ctime ?? decDate(buf, off + 488, 12)
147+
this.atime =
148+
ex?.atime ?? gex?.atime ?? decDate(buf, off + 476, 12)
149+
this.ctime =
150+
ex?.ctime ?? gex?.ctime ?? decDate(buf, off + 488, 12)
144151
/* c8 ignore stop */
145152
}
146153
}

src/mkdir.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,7 @@ const onmkdir =
151151
fs.mkdir(
152152
part,
153153
mode,
154-
onmkdir(
155-
part,
156-
parts,
157-
mode,
158-
unlink,
159-
cwd,
160-
created,
161-
cb,
162-
),
154+
onmkdir(part, parts, mode, unlink, cwd, created, cb),
163155
)
164156
})
165157
} else if (st.isSymbolicLink()) {
@@ -225,7 +217,9 @@ export const mkdirSync = (dir: string, opt: MkdirOptions) => {
225217
}
226218

227219
if (preserve) {
228-
return done(fs.mkdirSync(dir, { mode, recursive: true }) ?? undefined)
220+
return done(
221+
fs.mkdirSync(dir, { mode, recursive: true }) ?? undefined,
222+
)
229223
}
230224

231225
const sub = normalizeWindowsPath(path.relative(cwd, dir))

src/options.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ export interface TarOptions {
126126
/**
127127
* Set to `true` or an object with settings for `zstd.compress()` to
128128
* create a zstd-compressed archive
129-
*
129+
*
130130
* When extracting, this will cause the archive to be treated as a
131131
* zstd-compressed file if set to `true` or a ZlibOptions object.
132-
*
132+
*
133133
* If set `false`, then zstd options will not be used.
134-
*
134+
*
135135
* If this, the `gzip`, and `brotli` options are left `undefined`, then tar
136136
* will attempt to infer the zstd compression status, but can only do so
137137
* based on the filename. If the filename ends in `.tzst` or `.tar.zst`, and

src/pack.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,15 @@ export class Pack
129129
this.portable = !!opt.portable
130130

131131
if (opt.gzip || opt.brotli || opt.zstd) {
132-
if ((opt.gzip ? 1 : 0) + (opt.brotli ? 1 : 0) + (opt.zstd ? 1 : 0) > 1) {
133-
throw new TypeError('gzip, brotli, zstd are mutually exclusive')
132+
if (
133+
(opt.gzip ? 1 : 0) +
134+
(opt.brotli ? 1 : 0) +
135+
(opt.zstd ? 1 : 0) >
136+
1
137+
) {
138+
throw new TypeError(
139+
'gzip, brotli, zstd are mutually exclusive',
140+
)
134141
}
135142
if (opt.gzip) {
136143
if (typeof opt.gzip !== 'object') {

src/parse.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class Parser extends EE implements Warner {
140140
this.brotli =
141141
!(opt.gzip || opt.zstd) && opt.brotli !== undefined ? opt.brotli
142142
: isTBR ? undefined
143-
: false
143+
: false
144144

145145
// zstd has magic bytes to identify it, but we also support explicit options
146146
// and file extension detection
@@ -150,7 +150,7 @@ export class Parser extends EE implements Warner {
150150
this.zstd =
151151
!(opt.gzip || opt.brotli) && opt.zstd !== undefined ? opt.zstd
152152
: isTZST ? true
153-
: undefined
153+
: undefined
154154

155155
// have to set this so that streams are ok piping into it
156156
this.on('end', () => this[CLOSESTREAM]())
@@ -517,10 +517,8 @@ export class Parser extends EE implements Warner {
517517
const ended = this[ENDED]
518518
this[ENDED] = false
519519
this[UNZIP] =
520-
this[UNZIP] === undefined ?
521-
new Unzip({})
522-
: isZstd ?
523-
new ZstdDecompress({})
520+
this[UNZIP] === undefined ? new Unzip({})
521+
: isZstd ? new ZstdDecompress({})
524522
: new BrotliDecompress({})
525523
this[UNZIP].on('data', chunk => this[CONSUMECHUNK](chunk))
526524
this[UNZIP].on('error', er => this.abort(er as Error))

test/extract.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ t.test('zstd', async t => {
490490

491491
t.test('succeeds based on magic bytes', async t => {
492492
// copy the file to a new location with a different extension
493-
const unknownExtension = path.resolve(__dirname, 'zstd/example.unknown')
493+
const unknownExtension = path.resolve(
494+
__dirname,
495+
'zstd/example.unknown',
496+
)
494497
fs.copyFileSync(file, unknownExtension)
495498

496499
x({ sync: true, file: unknownExtension, C: dir })

test/header.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,16 @@ t.test('gnutar-generated 10gb file size', t => {
670670
t.end()
671671
})
672672

673-
t.test('tarmageddon, ensure that Header prioritizes Pax size', async t => {
674-
const h = new Header({
675-
path: 'file.txt',
676-
size: 0,
677-
})
678-
h.encode()
679-
t.equal(h.size, 0, 'size is zero in raw ustar header')
680-
const hPax = new Header(h.block, 0, { size: 123 })
681-
t.equal(hPax.size, 123, 'if size is set in pax, takes priority')
682-
})
673+
t.test(
674+
'tarmageddon, ensure that Header prioritizes Pax size',
675+
async t => {
676+
const h = new Header({
677+
path: 'file.txt',
678+
size: 0,
679+
})
680+
h.encode()
681+
t.equal(h.size, 0, 'size is zero in raw ustar header')
682+
const hPax = new Header(h.block, 0, { size: 123 })
683+
t.equal(hPax.size, 123, 'if size is set in pax, takes priority')
684+
},
685+
)

0 commit comments

Comments
 (0)