mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-31 23:25:13 +08:00
update 2026-10-07 18:47:42
This commit is contained in:
1 parent
617f7ca2a6
commit
bd061545ed
4832 files changed
+1693456
No files matched your search
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import fs from 'node:fs';
|
||||
|
||||
const [input, output] = process.argv.slice(2);
|
||||
|
||||
if (!input || !output) {
|
||||
console.error('usage: strip-tar-eof.mjs <input.tar> <output.tar>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const blockSize = 512;
|
||||
const data = fs.readFileSync(input);
|
||||
let end = data.length;
|
||||
|
||||
function isZeroBlock(offset) {
|
||||
for (let i = offset; i < offset + blockSize; i++) {
|
||||
if (data[i] !== 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
while (end >= blockSize && isZeroBlock(end - blockSize))
|
||||
end -= blockSize;
|
||||
|
||||
fs.writeFileSync(output, data.subarray(0, end));
|
||||
Reference in new issue
Block a user