Skip to content

Commit

Permalink
chore: lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Jun 20, 2023
1 parent c9fc57c commit eeba222
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 151 deletions.
3 changes: 1 addition & 2 deletions test/extract.js
Expand Up @@ -332,8 +332,7 @@ t.test('brotli', async t => {
x({ sync: true, file: file, C: dir, brotli: true })

t.same(fs.readdirSync(dir + '/x').sort(),
['1', '10', '2', '3', '4', '5', '6', '7', '8', '9'])
['1', '10', '2', '3', '4', '5', '6', '7', '8', '9'])
t.end()
})
})

292 changes: 145 additions & 147 deletions test/pack.js
Expand Up @@ -376,10 +376,10 @@ t.test('if gzip is truthy, make it an object', t => {
})

t.test('if brotli is truthy, make it an object', t => {
const opt = { brotli: true }
new Pack(opt)
t.type(opt.brotli, 'object')
t.end()
const opt = { brotli: true }
new Pack(opt)
t.type(opt.brotli, 'object')
t.end()
})

t.test('gzip, also a very deep path', t => {
Expand Down Expand Up @@ -462,82 +462,81 @@ t.test('gzip, also a very deep path', t => {
})

t.test('brotli, also a very deep path', t => {
const out = []
const out = []

new Pack({
cwd: files,
brotli: { flush: 1 },
})
.add('dir')
.add('long-path')
.on('data', c => out.push(c))
.end()
.on('end', _ => {
const zipped = Buffer.concat(out)
const data = zlib.brotliDecompressSync(zipped)
const entries = []
for (var i = 0; i < data.length; i += 512) {
const slice = data.slice(i, i + 512)
const h = new Header(slice)
if (h.nullBlock) {
entries.push('null block')
} else if (h.cksumValid) {
entries.push([h.type, h.path])
} else if (entries[entries.length - 1][0] === 'File') {
entries[entries.length - 1].push(slice.toString().replace(/\0.*$/, ''))
}
}

const expect = [
['Directory', 'dir/'],
['Directory', 'long-path/'],
['File', 'dir/x'],
['Directory', 'long-path/r/'],
['Directory', 'long-path/r/e/'],
['Directory', 'long-path/r/e/a/'],
['Directory', 'long-path/r/e/a/l/'],
['Directory', 'long-path/r/e/a/l/l/'],
['Directory', 'long-path/r/e/a/l/l/y/'],
['Directory', 'long-path/r/e/a/l/l/y/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/a.txt', 'short\n'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'],
['ExtendedHeader', 'PaxHeader/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222'],
['ExtendedHeader', 'PaxHeader/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccc'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccccccccccccc', 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'],
['ExtendedHeader', 'PaxHeader/Ω.txt'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/Ω.txt', 'Ω'],
'null block',
'null block',
]

let ok = true
entries.forEach((entry, i) => {
ok = ok &&
new Pack({
cwd: files,
brotli: { flush: 1 },
})
.add('dir')
.add('long-path')
.on('data', c => out.push(c))
.end()
.on('end', _ => {
const zipped = Buffer.concat(out)
const data = zlib.brotliDecompressSync(zipped)
const entries = []
for (var i = 0; i < data.length; i += 512) {
const slice = data.slice(i, i + 512)
const h = new Header(slice)
if (h.nullBlock) {
entries.push('null block')
} else if (h.cksumValid) {
entries.push([h.type, h.path])
} else if (entries[entries.length - 1][0] === 'File') {
entries[entries.length - 1].push(slice.toString().replace(/\0.*$/, ''))
}
}

const expect = [
['Directory', 'dir/'],
['Directory', 'long-path/'],
['File', 'dir/x'],
['Directory', 'long-path/r/'],
['Directory', 'long-path/r/e/'],
['Directory', 'long-path/r/e/a/'],
['Directory', 'long-path/r/e/a/l/'],
['Directory', 'long-path/r/e/a/l/l/'],
['Directory', 'long-path/r/e/a/l/l/y/'],
['Directory', 'long-path/r/e/a/l/l/y/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/a.txt', 'short\n'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'],
['ExtendedHeader', 'PaxHeader/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222'],
['ExtendedHeader', 'PaxHeader/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccc'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccccccccccccc', 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'],
['ExtendedHeader', 'PaxHeader/Ω.txt'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/Ω.txt', 'Ω'],
'null block',
'null block',
]

let ok = true
entries.forEach((entry, i) => {
ok = ok &&
t.equal(entry[0], expect[i][0]) &&
t.equal(entry[1], expect[i][1]) &&
(!entry[2] || t.equal(entry[2], expect[i][2]))
})
})

// t.match(entries, expect)
t.end()
})
t.end()
})
})

t.test('very deep gzip path, sync', t => {
Expand Down Expand Up @@ -620,82 +619,81 @@ t.test('very deep gzip path, sync', t => {
})

t.test('very deep brotli path, sync', t => {
const pack = new PackSync({
cwd: files,
brotli: true,
}).add('dir')
.add('long-path')
.end()

// these do nothing!
pack.pause()
pack.resume()

const zipped = pack.read()
t.type(zipped, Buffer)
const data = zlib.brotliDecompressSync(zipped)
const entries = []
for (var i = 0; i < data.length; i += 512) {
const slice = data.slice(i, i + 512)
const h = new Header(slice)
if (h.nullBlock) {
entries.push('null block')
} else if (h.cksumValid) {
entries.push([h.type, h.path])
} else if (entries[entries.length - 1][0] === 'File') {
entries[entries.length - 1].push(slice.toString().replace(/\0.*$/, ''))
}
const pack = new PackSync({
cwd: files,
brotli: true,
}).add('dir')
.add('long-path')
.end()

// these do nothing!
pack.pause()
pack.resume()

const zipped = pack.read()
t.type(zipped, Buffer)
const data = zlib.brotliDecompressSync(zipped)
const entries = []
for (var i = 0; i < data.length; i += 512) {
const slice = data.slice(i, i + 512)
const h = new Header(slice)
if (h.nullBlock) {
entries.push('null block')
} else if (h.cksumValid) {
entries.push([h.type, h.path])
} else if (entries[entries.length - 1][0] === 'File') {
entries[entries.length - 1].push(slice.toString().replace(/\0.*$/, ''))
}
}

const expect = [
['Directory', 'dir/'],
['File', 'dir/x'],
['Directory', 'long-path/'],
['Directory', 'long-path/r/'],
['Directory', 'long-path/r/e/'],
['Directory', 'long-path/r/e/a/'],
['Directory', 'long-path/r/e/a/l/'],
['Directory', 'long-path/r/e/a/l/l/'],
['Directory', 'long-path/r/e/a/l/l/y/'],
['Directory', 'long-path/r/e/a/l/l/y/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/a.txt', 'short\n'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'],
['ExtendedHeader', 'PaxHeader/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222'],
['ExtendedHeader', 'PaxHeader/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccc'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccccccccccccc', 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'],
['ExtendedHeader', 'PaxHeader/Ω.txt'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/Ω.txt', 'Ω'],
'null block',
'null block',
]
const expect = [
['Directory', 'dir/'],
['File', 'dir/x'],
['Directory', 'long-path/'],
['Directory', 'long-path/r/'],
['Directory', 'long-path/r/e/'],
['Directory', 'long-path/r/e/a/'],
['Directory', 'long-path/r/e/a/l/'],
['Directory', 'long-path/r/e/a/l/l/'],
['Directory', 'long-path/r/e/a/l/l/y/'],
['Directory', 'long-path/r/e/a/l/l/y/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/'],
['Directory', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/a.txt', 'short\n'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'],
['ExtendedHeader', 'PaxHeader/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', '2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222'],
['ExtendedHeader', 'PaxHeader/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccc'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxccccccccccccccccccccccccccccccccccccccccccccccccc', 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'],
['ExtendedHeader', 'PaxHeader/Ω.txt'],
['File', 'long-path/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/Ω.txt', 'Ω'],
'null block',
'null block',
]

let ok = true
entries.forEach((entry, i) => {
ok = ok &&
t.equal(entry[0], expect[i][0]) &&
t.equal(entry[1], expect[i][1]) &&
(!entry[2] || t.equal(entry[2], expect[i][2]))
})
let ok = true
entries.forEach((entry, i) => {
ok = ok &&
t.equal(entry[0], expect[i][0]) &&
t.equal(entry[1], expect[i][1]) &&
(!entry[2] || t.equal(entry[2], expect[i][2]))
})

// t.match(entries, expect)
t.end()
t.end()
})

t.test('write after end', t => {
Expand Down
2 changes: 1 addition & 1 deletion test/parse.js
Expand Up @@ -130,7 +130,7 @@ t.test('fixture tests', t => {
maxMetaEntrySize: maxMeta,
filter: filter ? (path, entry) => entry.size % 2 !== 0 : null,
strict: strict,
brotli: {}
brotli: {},
})
trackEvents(t, expect, p)
p.end(zlib.brotliCompressSync(tardata))
Expand Down
1 change: 0 additions & 1 deletion test/update.js
Expand Up @@ -9,7 +9,6 @@ const { resolve } = require('path')
const fixtures = path.resolve(__dirname, 'fixtures')
const tars = path.resolve(fixtures, 'tars')
const zlib = require('zlib')
const r = require("../lib/replace");

const spawn = require('child_process').spawn

Expand Down

0 comments on commit eeba222

Please sign in to comment.