diff --git a/shell/cdimage.ts b/shell/cdimage.ts
index d69ab58..a96af2c 100644
--- a/shell/cdimage.ts
+++ b/shell/cdimage.ts
@@ -1,5 +1,4 @@
///
-///
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';
diff --git a/shell/text-decoder.ts b/shell/text-decoder.ts
deleted file mode 100644
index 7178d9d..0000000
--- a/shell/text-decoder.ts
+++ /dev/null
@@ -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 (!(window).TextDecoder)
- (window).TextDecoder = FallbackTextDecoder;
diff --git a/shell/util.ts b/shell/util.ts
index 75d9f0b..c1bb63f 100644
--- a/shell/util.ts
+++ b/shell/util.ts
@@ -18,6 +18,25 @@ function readFileAsText(blob: Blob): Promise {
});
}
+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