25 lines
614 B
TypeScript
25 lines
614 B
TypeScript
import {Converter} from './converter';
|
|
import {NativeLibraryWrapperService} from '../nativelibrarywrapper.service';
|
|
|
|
export class UTF8Decoder implements Converter {
|
|
|
|
constructor(private nativeLibraryWrapperService: NativeLibraryWrapperService) {
|
|
}
|
|
|
|
getDisplayname(): string {
|
|
return 'Decode UTF-8';
|
|
}
|
|
|
|
getId(): string {
|
|
return 'decodeutf8';
|
|
}
|
|
|
|
convert(input: string): string {
|
|
try {
|
|
return this.nativeLibraryWrapperService.utf8.decode(input);
|
|
} catch (error) {
|
|
throw new Error('The input can not be interpreted a valid UTF-8 encoded string. May be corrupt?');
|
|
}
|
|
}
|
|
}
|