nyuu's 12 capital+small letter pairs in 15 bytes (10 bits a pair), its timestamp as a delta within the file, the suffix once per file; ngPost-style 32 hex digits in 16 bytes; other ids as zstd text as before. Recent boneless: 25.2 → 20.3 B per segment (and 25.0 → 19.5 on the next range); a 2013 ath range stays at 17.9 (JBinUp ids are text). Every chunk of three real ranges decodes to itself (edge:bench --verify). Encoding is no slower than v1 (less text for zstd). Version 1 chunks stay readable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
2.5 KiB
TypeScript
42 lines
2.5 KiB
TypeScript
import { test } from '@japa/runner'
|
|
import { decodeChunk, encodeChunk, type ChunkFile } from '#lib/chunks/index'
|
|
|
|
test.group('chunks / codec', () => {
|
|
test('round-trips files with their segments, part numbers when not 1..N', ({ assert }) => {
|
|
const files: ChunkFile[] = [
|
|
{ name: 'a.part1.rar', poster: 'p <p@x>', subject: 'A [1/2] - "a.part1.rar" yEnc', postedAt: 1_700_000_000_000, groups: ['alt.binaries.test'], segments: [[1, 'one@x', 700_000], [2, 'two@x', 1234]] },
|
|
{ name: 'a.par2', poster: 'p <p@x>', subject: 'A [2/2] - "a.par2" yEnc', postedAt: null, groups: ['alt.binaries.test', 'alt.binaries.x'], segments: [[2, 'gap@x', 10], [5, 'gap2@x', 11]] },
|
|
]
|
|
const data = encodeChunk(files)
|
|
assert.equal(data[0], 2)
|
|
assert.deepEqual(decodeChunk(data), files)
|
|
})
|
|
|
|
test('nyuu and hex ids as bits, others as text, all exactly back', ({ assert }) => {
|
|
const files: ChunkFile[] = [
|
|
{ name: 'n.part1.rar', poster: 'p', subject: 'n', postedAt: 1, groups: ['a.b.x'],
|
|
segments: [[1, 'FmFwIaTpGgUiSfYcMwFlMeRo-1790637260478@nyuu', 716800], [2, 'ZzAaYyBbXxCcWwDdVvEeUuFf-1790637260490@nyuu', 716800], [3, 'AaAaAaAaAaAaAaAaAaAaAaAa-0790637260500@nyuu', 5]] },
|
|
{ name: 'h.part1.rar', poster: 'p', subject: 'h', postedAt: 2, groups: ['a.b.x'],
|
|
segments: [[1, 'b94268bc702040f7b811d5318f727e4f@ngPost', 700000], [2, '00000000000000000000000000000000@ngPost', 1]] },
|
|
// Mixed suffixes: kept as text.
|
|
{ name: 'm.bin', poster: 'p', subject: 'm', postedAt: null, groups: ['a.b.x'],
|
|
segments: [[1, 'b94268bc702040f7b811d5318f727e4f@ngPost', 1], [3, 'b94268bc702040f7b811d5318f727e4f@other', 2]] },
|
|
{ name: 't.nfo', poster: 'p', subject: 't', postedAt: 3, groups: ['a.b.x'], segments: [[1, 'part1of1.abc@JBinUp.local', 9]] },
|
|
]
|
|
const data = encodeChunk(files)
|
|
assert.equal(data[0], 2)
|
|
assert.deepEqual(decodeChunk(data), files)
|
|
})
|
|
|
|
test('reads version 1 chunks', async ({ assert }) => {
|
|
const { zstdCompressSync } = await import('node:zlib')
|
|
const head = JSON.stringify([{ n: 'a.rar', p: 'p', j: 'a', d: 5, g: ['a.b.x'], s: [10, 20] }])
|
|
const v1 = Buffer.concat([Buffer.from([1]), zstdCompressSync(Buffer.from([head, 'one@x', 'two@x'].join('\n')))])
|
|
assert.deepEqual(decodeChunk(v1), [{ name: 'a.rar', poster: 'p', subject: 'a', postedAt: 5, groups: ['a.b.x'], segments: [[1, 'one@x', 10], [2, 'two@x', 20]] }])
|
|
})
|
|
|
|
test('refuses an unknown version', ({ assert }) => {
|
|
assert.throws(() => decodeChunk(Buffer.from([9, 0])), /Unknown chunk version 9/)
|
|
})
|
|
})
|