feat(archive): add MIME types and compound-extension aliases for archive formats
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -242,3 +242,38 @@ describe('resolveInputFormat — dfont', () => {
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
});
|
||||
|
||||
describe('outputMimeType — archives', () => {
|
||||
it('returns the correct MIME type for each archive target format', () => {
|
||||
expect(outputMimeType('zip')).toBe('application/zip');
|
||||
expect(outputMimeType('tar')).toBe('application/x-tar');
|
||||
expect(outputMimeType('tar.gz')).toBe('application/gzip');
|
||||
expect(outputMimeType('tar.bz2')).toBe('application/x-bzip2');
|
||||
expect(outputMimeType('7z')).toBe('application/x-7z-compressed');
|
||||
expect(outputMimeType('tar.7z')).toBe('application/x-7z-compressed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveInputFormat — compound archive extensions', () => {
|
||||
it('accepts a real gzip file declared as tar.gz (file-type sniffs the outer gzip layer only)', async () => {
|
||||
const zlib = await import('node:zlib');
|
||||
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample.tar.gz');
|
||||
await fs.writeFile(fixturePath, zlib.gzipSync(Buffer.from('irrelevant payload for this check')));
|
||||
|
||||
const result = await resolveInputFormat(fixturePath, 'tar.gz');
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
|
||||
it('accepts a real 7z file declared as tar.7z (file-type sniffs the outer 7z layer only)', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample.tar.7z');
|
||||
// Minimal valid 7z signature header (6-byte magic + 2-byte version), enough for file-type to sniff `ext: '7z'`.
|
||||
await fs.writeFile(fixturePath, Buffer.from([0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c, 0x00, 0x04]));
|
||||
|
||||
const result = await resolveInputFormat(fixturePath, 'tar.7z');
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
await fs.unlink(fixturePath);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user