feat(archive): add 7z and tar.7z converters
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -161,3 +161,70 @@ describe('archive converters — tar.bz2', () => {
|
||||
20000
|
||||
);
|
||||
});
|
||||
|
||||
describe('archive converters — 7z and tar.7z', () => {
|
||||
it('registers 7z and tar.7z as targets for each other and for zip', () => {
|
||||
expect(listTargetFormats('zip')).toContain('7z');
|
||||
expect(listTargetFormats('zip')).toContain('tar.7z');
|
||||
expect(listTargetFormats('7z')).toContain('tar.7z');
|
||||
});
|
||||
|
||||
it(
|
||||
'converts zip -> 7z, preserving nested paths and content',
|
||||
async () => {
|
||||
const zipPath = path.join(tmpDir, 'for-7z.zip');
|
||||
buildZipFixture(zipPath);
|
||||
const sevenZPath = path.join(tmpDir, 'output.7z');
|
||||
|
||||
await resolve('zip', '7z').convert(zipPath, sevenZPath, { quality: 9 });
|
||||
|
||||
const listDir = await fs.mkdtemp(path.join(os.tmpdir(), '7z-check-'));
|
||||
await resolve('7z', 'zip').convert(sevenZPath, path.join(listDir, 'roundtrip.zip'));
|
||||
const rtZip = new AdmZip(path.join(listDir, 'roundtrip.zip'));
|
||||
expect(rtZip.readAsText('hello.txt')).toBe('hello world');
|
||||
expect(rtZip.readAsText('nested/inner.txt')).toBe('nested content');
|
||||
await fs.rm(listDir, { recursive: true, force: true });
|
||||
},
|
||||
20000
|
||||
);
|
||||
|
||||
it(
|
||||
'converts zip -> tar.7z -> tar, preserving content',
|
||||
async () => {
|
||||
const zipPath = path.join(tmpDir, 'for-tar7z.zip');
|
||||
buildZipFixture(zipPath);
|
||||
const tar7zPath = path.join(tmpDir, 'output.tar.7z');
|
||||
|
||||
await resolve('zip', 'tar.7z').convert(zipPath, tar7zPath, { quality: 5 });
|
||||
|
||||
const backToTarPath = path.join(tmpDir, 'from-tar7z.tar');
|
||||
await resolve('tar.7z', 'tar').convert(tar7zPath, backToTarPath);
|
||||
|
||||
const listDir = await fs.mkdtemp(path.join(os.tmpdir(), 'tar7z-check-'));
|
||||
await tar.extract({ file: backToTarPath, cwd: listDir });
|
||||
expect(await fs.readFile(path.join(listDir, 'hello.txt'), 'utf8')).toBe('hello world');
|
||||
await fs.rm(listDir, { recursive: true, force: true });
|
||||
},
|
||||
20000
|
||||
);
|
||||
|
||||
it(
|
||||
'produces a smaller-or-equal 7z at a higher compression level',
|
||||
async () => {
|
||||
const zipPath = path.join(tmpDir, 'for-7z-level.zip');
|
||||
const zip = new AdmZip();
|
||||
zip.addFile('big.txt', Buffer.from('ab'.repeat(100000)));
|
||||
zip.writeZip(zipPath);
|
||||
|
||||
const lowPath = path.join(tmpDir, 'low.7z');
|
||||
const highPath = path.join(tmpDir, 'high.7z');
|
||||
|
||||
await resolve('zip', '7z').convert(zipPath, lowPath, { quality: 0 });
|
||||
await resolve('zip', '7z').convert(zipPath, highPath, { quality: 9 });
|
||||
|
||||
const [lowStat, highStat] = await Promise.all([fs.stat(lowPath), fs.stat(highPath)]);
|
||||
expect(highStat.size).toBeLessThanOrEqual(lowStat.size);
|
||||
},
|
||||
20000
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user