-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConverterManager.ts
More file actions
21 lines (16 loc) · 851 Bytes
/
ConverterManager.ts
File metadata and controls
21 lines (16 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import {type BufferAccess} from '../common/BufferAccess.js';
import {FormatNotFoundError} from '../common/Exceptions.js';
import {OptionContainer, type OptionValues} from '../encoding/Options.js';
import {converters} from './ConverterProvider.js';
import {type PublicConverterDefinition, type ConverterDefinition} from './converter/ConverterDefinition.js';
export function getConverters(): PublicConverterDefinition[] {
return converters;
}
export function convert(data: BufferAccess, identifier: string, options: OptionValues): BufferAccess {
const chosenConverters = converters.filter((c: ConverterDefinition) => c.identifier === identifier);
if (chosenConverters.length === 0) {
throw new FormatNotFoundError(identifier);
}
const converter = chosenConverters[0];
return converter.convert(data, new OptionContainer(options));
}