feat(archive): add tar and tar.gz converters

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 12:51:34 +02:00
co-authored by Claude Sonnet 5
parent d68694ead8
commit c9251e66e2
4 changed files with 127 additions and 2 deletions
+19 -2
View File
@@ -4,6 +4,7 @@ import path from 'node:path';
import os from 'node:os';
import AdmZip from 'adm-zip';
import { ZipArchive } from 'archiver';
import * as tar from 'tar';
import { register } from './registry.js';
const MAX_EXTRACTED_BYTES = 2 * 1024 * 1024 * 1024;
@@ -53,8 +54,24 @@ function createZip(srcDir, outputPath, quality) {
});
}
const EXTRACTORS = { zip: extractZip };
const CREATORS = { zip: createZip };
async function extractTarLike(inputPath, destDir) {
// tar's extract auto-detects gzip compression from the file's magic bytes,
// so the same function handles both plain .tar and .tar.gz input.
await tar.extract({ file: inputPath, cwd: destDir });
}
async function createTar(srcDir, outputPath) {
const entries = await fs.readdir(srcDir);
await tar.create({ file: outputPath, cwd: srcDir }, entries);
}
async function createTarGz(srcDir, outputPath, quality) {
const entries = await fs.readdir(srcDir);
await tar.create({ file: outputPath, cwd: srcDir, gzip: { level: quality ?? 6 } }, entries);
}
const EXTRACTORS = { zip: extractZip, tar: extractTarLike, 'tar.gz': extractTarLike };
const CREATORS = { zip: createZip, tar: createTar, 'tar.gz': createTarGz };
async function convert(inputPath, outputPath, options, sourceFormat, targetFormat) {
const { quality } = options ?? {};