/** * One XOVER chunk fetched compressed (with a reply timeout) and plain, timed: * whether a chunk that never finishes compressed is whole without compression. * * node --env-file=.env --import=@poppinss/ts-exec tools/probe_chunk.ts [timeoutSeconds] */ import { unzipSync } from 'node:zlib' import { XoverClient } from '#lib/nntp/index' const [group, from, to, timeout] = process.argv.slice(2) const env = process.env const connect = (compress: boolean, timeoutMs: number) => XoverClient.connect({ host: env.NNTP_HOST!, port: Number(env.NNTP_PORT ?? 563), user: env.NNTP_USER, password: env.NNTP_PASSWORD, secure: (env.NNTP_SECURE ?? 'true') !== 'false', compress, timeoutMs }) for (const compress of [true, false]) { const c = await connect(compress, Number(timeout ?? 90) * 1000) await c.group(group) const at = Date.now() try { const raw = await c.xoverRaw(Number(from), Number(to)) const lines = unzipSync(raw).toString().split('\r\n').filter((l) => l.includes('\t')).length console.log(`${compress ? 'compressed' : 'plain'}: ${raw.length} bytes, ${lines} lines in ${((Date.now() - at) / 1000).toFixed(1)} s`) } catch (e: any) { console.log(`${compress ? 'compressed' : 'plain'}: ${e.message} after ${((Date.now() - at) / 1000).toFixed(1)} s`) } c.close() }