mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-10-04 12:48:00 +03:00
Do not mock TextDecoder
This commit is contained in:
+3
-6
@@ -1,5 +1,4 @@
|
||||
/// <reference path="util.ts" />
|
||||
/// <reference path="text-decoder.ts" />
|
||||
|
||||
namespace CDImage {
|
||||
export class ISO9660FileSystem {
|
||||
@@ -72,8 +71,7 @@ namespace CDImage {
|
||||
return this.view.getUint8(0);
|
||||
}
|
||||
volumeLabel(): string {
|
||||
let decoder = new TextDecoder('shift_jis');
|
||||
return decoder.decode(new DataView(this.buf, 40, 32)).trim();
|
||||
return SJISArrayToString(new DataView(this.buf, 40, 32)).trim();
|
||||
}
|
||||
rootDirEnt(): DirEnt {
|
||||
return new DirEnt(this.buf, 156);
|
||||
@@ -99,8 +97,7 @@ namespace CDImage {
|
||||
}
|
||||
get name(): string {
|
||||
let len = this.view.getUint8(32);
|
||||
let decoder = new TextDecoder('shift_jis');
|
||||
return decoder.decode(new DataView(this.buf, this.offset + 33, len)).split(';')[0];
|
||||
return SJISArrayToString(new DataView(this.buf, this.offset + 33, len)).split(';')[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +216,7 @@ namespace CDImage {
|
||||
async parseMds(mdsFile: File) {
|
||||
let buf = await readFileAsArrayBuffer(mdsFile);
|
||||
|
||||
let signature = new TextDecoder().decode(new DataView(buf, 0, 16));
|
||||
let signature = ASCIIArrayToString(new Uint8Array(buf, 0, 16));
|
||||
if (signature !== 'MEDIA DESCRIPTOR')
|
||||
throw mdsFile.name + ': not a mds file';
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
class FallbackTextDecoder {
|
||||
constructor(utfLabel?: string) {}
|
||||
|
||||
decode(buffer: DataView): string {
|
||||
let out = '';
|
||||
for (let i = 0; i < buffer.byteLength; i++) {
|
||||
let c = buffer.getUint8(i);
|
||||
if (c < 128)
|
||||
out += String.fromCharCode(c);
|
||||
else
|
||||
out += '%' + c.toString(16);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(<any>window).TextDecoder)
|
||||
(<any>window).TextDecoder = <TextEncoding.TextDecoderStatic>FallbackTextDecoder;
|
||||
@@ -18,6 +18,25 @@ function readFileAsText(blob: Blob): Promise<string> {
|
||||
});
|
||||
}
|
||||
|
||||
function ASCIIArrayToString(buffer: Uint8Array): string {
|
||||
return String.fromCharCode.apply(null, buffer);
|
||||
}
|
||||
|
||||
function SJISArrayToString(buffer: DataView): string {
|
||||
if (typeof TextDecoder !== 'undefined')
|
||||
return new TextDecoder('shift_jis').decode(buffer);
|
||||
|
||||
let out = '';
|
||||
for (let i = 0; i < buffer.byteLength; i++) {
|
||||
let c = buffer.getUint8(i);
|
||||
if (c < 128)
|
||||
out += String.fromCharCode(c);
|
||||
else
|
||||
out += '%' + c.toString(16);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
declare var WebAssembly: any;
|
||||
|
||||
// xsystem35 exported functions
|
||||
|
||||
Reference in New Issue
Block a user