Rebuild: chunk format v2 — nyuu and hex message-ids as bits
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>
This commit is contained in:
1 parent
31493a98be
commit
e9592dfd33
3 files changed
+197
-14
No files matched your search
@@ -8,10 +8,33 @@ test.group('chunks / codec', () => {
|
||||
{ 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], 1)
|
||||
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/)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user