feat(archive): add tar and tar.gz converters
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 ?? {};
|
||||
|
||||
Reference in New Issue
Block a user