diff --git a/packages/web/package.json b/packages/web/package.json index 20a857be..98975086 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -31,6 +31,7 @@ "diff": "^5.0.0", "diff2html": "^3.4.13", "file-selector": "^0.2.4", + "iconv-lite": "^0.6.3", "js-yaml": "^4.1.0", "json-stable-stringify": "^1.0.1", "localforage": "^1.9.0", diff --git a/packages/web/src/utility/openElectronFile.ts b/packages/web/src/utility/openElectronFile.ts index 6cf8ec36..f5b341ee 100644 --- a/packages/web/src/utility/openElectronFile.ts +++ b/packages/web/src/utility/openElectronFile.ts @@ -55,11 +55,16 @@ function getFileEncoding(filePath, fs) { if (!e && buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) e = 'utf8'; if (!e && buf[0] === 0xfe && buf[1] === 0xff) e = 'utf16be'; if (!e && buf[0] === 0xff && buf[1] === 0xfe) e = 'utf16le'; - if (!e) e = 'ascii'; + if (!e) e = 'utf8'; return e; } +function decodeFile(buf: Uint8Array, enc: string) { + const iconv = window.require('iconv-lite'); + return iconv.decode(buf, enc); +} + function openElectronJsonLinesFile(filePath, parsed) { openNewTab({ title: parsed.name, @@ -115,7 +120,8 @@ export function openElectronFileCore(filePath, extensions) { if (nameLower.endsWith('.sql')) { const encoding = getFileEncoding(filePath, fs); - const data = fs.readFileSync(filePath, { encoding }); + const buf = fs.readFileSync(filePath); + const data = decodeFile(buf, encoding); newQuery({ title: parsed.name,