Skip to content

Commit

Permalink
remove more cruft, format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Apr 16, 2024
1 parent faf9359 commit bead873
Show file tree
Hide file tree
Showing 38 changed files with 1,198 additions and 955 deletions.
10 changes: 0 additions & 10 deletions .commitlintrc.js

This file was deleted.

17 changes: 0 additions & 17 deletions .eslintrc.js

This file was deleted.

16 changes: 0 additions & 16 deletions .eslintrc.local.js

This file was deleted.

380 changes: 190 additions & 190 deletions README.md

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions map.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { basename } from 'path'

const map = test =>
test === 'map.js'
? test
: test === 'unpack.js'
? ['src/unpack.ts', 'src/mkdir.ts']
: test === 'load-all.js'
? []
: `src/${test.replace(/js$/, 'ts')}`
test === 'map.js' ? test
: test === 'unpack.js' ? ['src/unpack.ts', 'src/mkdir.ts']
: test === 'load-all.js' ? []
: `src/${test.replace(/js$/, 'ts')}`

export default test => map(basename(test))
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags",
"format": "prettier --write . --loglevel warn",
"format": "prettier --write . --log-level warn",
"typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts"
},
"dependencies": {
Expand Down Expand Up @@ -52,6 +52,7 @@
"timeout": 0
},
"prettier": {
"experimentalTernaries": true,
"semi": false,
"printWidth": 70,
"tabWidth": 2,
Expand Down
127 changes: 70 additions & 57 deletions scripts/generate-parse-fixtures.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Parser } from '../dist/esm/parse.js'
import fs from 'fs'
import path, {dirname, resolve} from 'path'
import {fileURLToPath} from 'url'
import path, { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

Expand All @@ -17,7 +17,8 @@ const makeTest = (tarfile, tardata, maxMeta, filter, strict) => {
(filter ? '-filter' : '') +
(strict ? '-strict' : '')
const tail = (o ? '-' + o : '') + '.json'
const eventsfile = parsedir + '/' + path.basename(tarfile, '.tar') + tail
const eventsfile =
parsedir + '/' + path.basename(tarfile, '.tar') + tail

const p = new Parser({
maxMetaEntrySize: maxMeta,
Expand All @@ -27,57 +28,67 @@ const makeTest = (tarfile, tardata, maxMeta, filter, strict) => {
const events = []

const pushEntry = type => entry => {
events.push([type, {
extended: entry.extended,
globalExtended: entry.globalExtended,
type: entry.type,
meta: entry.meta,
ignore: entry.ignore,
path: entry.path,
mode: entry.mode,
uid: entry.uid,
gid: entry.gid,
uname: entry.uname,
gname: entry.gname,
size: entry.size,
mtime: entry.mtime,
atime: entry.atime,
ctime: entry.ctime,
linkpath: entry.linkpath,
header: {
cksumValid: entry.header.cksumValid,
needPax: entry.header.needPax,
path: entry.header.path,
mode: entry.header.mode,
uid: entry.header.uid,
gid: entry.header.gid,
size: entry.header.size,
mtime: entry.header.mtime,
cksum: entry.header.cksum,
linkpath: entry.header.linkpath,
ustar: entry.header.ustar,
ustarver: entry.header.ustarver,
uname: entry.header.uname,
gname: entry.header.gname,
devmaj: entry.header.devmaj,
devmin: entry.header.devmin,
ustarPrefix: entry.header.ustarPrefix,
xstarPrefix: entry.header.xstarPrefix,
prefixTerminator: entry.header.prefixTerminator,
atime: entry.header.atime,
ctime: entry.header.atime,
events.push([
type,
{
extended: entry.extended,
globalExtended: entry.globalExtended,
type: entry.type,
meta: entry.meta,
ignore: entry.ignore,
path: entry.path,
mode: entry.mode,
uid: entry.uid,
gid: entry.gid,
uname: entry.uname,
gname: entry.gname,
size: entry.size,
mtime: entry.mtime,
atime: entry.atime,
ctime: entry.ctime,
linkpath: entry.linkpath,
header: {
cksumValid: entry.header.cksumValid,
needPax: entry.header.needPax,
path: entry.header.path,
mode: entry.header.mode,
uid: entry.header.uid,
gid: entry.header.gid,
size: entry.header.size,
mtime: entry.header.mtime,
cksum: entry.header.cksum,
linkpath: entry.header.linkpath,
ustar: entry.header.ustar,
ustarver: entry.header.ustarver,
uname: entry.header.uname,
gname: entry.header.gname,
devmaj: entry.header.devmaj,
devmin: entry.header.devmin,
ustarPrefix: entry.header.ustarPrefix,
xstarPrefix: entry.header.xstarPrefix,
prefixTerminator: entry.header.prefixTerminator,
atime: entry.header.atime,
ctime: entry.header.atime,
},
},
}])
])
entry.resume()
}

p.on('entry', pushEntry('entry'))
p.on('ignoredEntry', pushEntry('ignoredEntry'))
p.on('warn', (code, message, _data) => events.push(['warn', code, message]))
p.on('error', er => events.push(['error', {
message: er.message,
code: er.code,
}]))
p.on('warn', (code, message, _data) =>
events.push(['warn', code, message]),
)
p.on('error', er =>
events.push([
'error',
{
message: er.message,
code: er.code,
},
]),
)
p.on('end', _ => events.push(['end']))
p.on('nullBlock', _ => events.push(['nullBlock']))
p.on('eof', _ => events.push(['eof']))
Expand All @@ -88,12 +99,14 @@ const makeTest = (tarfile, tardata, maxMeta, filter, strict) => {
fs.writeFileSync(eventsfile, JSON.stringify(events, null, 2) + '\n')
}

fs.readdirSync(tardir)
.forEach(tar => {
const tarfile = tardir + '/' + tar
const tardata = fs.readFileSync(tarfile)
maxMetaOpt.forEach(maxMeta =>
filterOpt.forEach(filter =>
strictOpt.forEach(strict =>
makeTest(tarfile, tardata, maxMeta, filter, strict))))
})
fs.readdirSync(tardir).forEach(tar => {
const tarfile = tardir + '/' + tar
const tardata = fs.readFileSync(tarfile)
maxMetaOpt.forEach(maxMeta =>
filterOpt.forEach(filter =>
strictOpt.forEach(strict =>
makeTest(tarfile, tardata, maxMeta, filter, strict),
),
),
)
})
13 changes: 6 additions & 7 deletions src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ export function create(
throw new TypeError('callback only supported with file option')
}

return isSyncFile(opt)
? createFileSync(opt, files)
: isFile(opt)
? createFile(opt, files, cb)
: isSync(opt)
? createSync(opt, files)
: create_(opt, files)
return (
isSyncFile(opt) ? createFileSync(opt, files)
: isFile(opt) ? createFile(opt, files, cb)
: isSync(opt) ? createSync(opt, files)
: create_(opt, files)
)
}

const createFileSync = (opt: TarOptionsSyncFile, files: string[]) => {
Expand Down
23 changes: 10 additions & 13 deletions src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ export function extract(
filesFilter(opt, files)
}

return isSyncFile(opt)
? extractFileSync(opt)
: isFile(opt)
? extractFile(opt, cb)
: isSync(opt)
? extractSync(opt)
: extract_(opt)
return (
isSyncFile(opt) ? extractFileSync(opt)
: isFile(opt) ? extractFile(opt, cb)
: isSync(opt) ? extractSync(opt)
: extract_(opt)
)
}

// construct a filter that limits the file entries listed
Expand All @@ -109,8 +108,9 @@ const filesFilter = (opt: TarOptions, files: string[]) => {
return ret
}

opt.filter = filter
? (file, entry) =>
opt.filter =
filter ?
(file, entry) =>
filter(file, entry) && mapHas(stripTrailingSlashes(file))
: file => mapHas(stripTrailingSlashes(file))
}
Expand All @@ -130,10 +130,7 @@ const extractFileSync = (opt: TarOptionsSyncFile) => {
stream.pipe(u)
}

const extractFile = (
opt: TarOptionsFile,
cb?: () => void,
) => {
const extractFile = (opt: TarOptionsFile, cb?: () => void) => {
const u = new Unpack(opt)
const readSize = opt.maxReadSize || 16 * 1024 * 1024

Expand Down
5 changes: 3 additions & 2 deletions src/get-write-flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const UV_FS_O_FILEMAP =
const fMapEnabled = isWindows && !!UV_FS_O_FILEMAP
const fMapLimit = 512 * 1024
const fMapFlag = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY
export const getWriteFlag = !fMapEnabled
? () => 'w'
export const getWriteFlag =
!fMapEnabled ?
() => 'w'
: (size: number) => (size < fMapLimit ? fMapFlag : 'w')
Loading

0 comments on commit bead873

Please sign in to comment.