http-range-desk / cli.mjs
WideChaos's picture
Publish HTTP Range Desk 0.1.0
78e7c43 verified
Raw History Blame Contribute Delete
807 Bytes
/* Copyright 2026 Renchao Wu. Apache-2.0. */
import fs from'node:fs';import{parseRequest,makeReport}from'./core.mjs';if(![4,5].includes(process.argv.length)){console.error('Usage: node cli.mjs REQUEST.json NEW-REPORT.json [LOCAL-PAYLOAD.bin]');process.exitCode=2;}else try{let[request,out,file]=process.argv.slice(2);function bounded(p,cap){let s=fs.lstatSync(p);if(!s.isFile()||s.size>cap)throw Error('Expected bounded regular input');return fs.readFileSync(p);}let q=parseRequest(bounded(request,65536).toString('utf8')),p=file?new Uint8Array(bounded(file,1048576)):null,r=await makeReport(q,p);fs.writeFileSync(out,JSON.stringify(r,null,2)+'\n',{flag:'wx',mode:0o600});console.log('Local range plan written; no HTTP request made.');}catch(e){console.error('Plan failed: '+e.message);process.exitCode=2;}