From 4e0d5f1641bb1a3fa700d1384df0fa9ce04149f6 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Mon, 30 Oct 2023 13:03:48 +0100 Subject: [PATCH] Include encoding param --- .../src/app/services/circomPluginClient.ts | 4 ++-- apps/remix-ide/src/app/files/fileManager.ts | 22 +++++++++---------- apps/remix-ide/src/app/files/fileProvider.js | 10 ++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/apps/circuit-compiler/src/app/services/circomPluginClient.ts b/apps/circuit-compiler/src/app/services/circomPluginClient.ts index 030db67972..4d887e996b 100644 --- a/apps/circuit-compiler/src/app/services/circomPluginClient.ts +++ b/apps/circuit-compiler/src/app/services/circomPluginClient.ts @@ -143,7 +143,7 @@ export class CircomPluginClient extends PluginClient { this.lastCompiledCircuitPath = extractParentFromKey(path) + "/.bin/" + fileName.replace('circom', 'wasm') // @ts-ignore - await this.call('fileManager', 'writeFile', this.lastCompiledCircuitPath, circuitProgram, true) + await this.call('fileManager', 'writeFile', this.lastCompiledCircuitPath, circuitProgram, { encoding: null }) const fileContent = this.lastParsedFiles[path] const searchComponentName = fileContent.match(/component\s+main\s*(?:{[^{}]*})?\s*=\s*([A-Za-z_]\w*)\s*\(.*\)/) @@ -201,7 +201,7 @@ export class CircomPluginClient extends PluginClient { if (!wasmPath) throw new Error('No wasm file found') // @ts-ignore - const buffer: any = await this.call('fileManager', 'readFile', wasmPath, true) + const buffer: any = await this.call('fileManager', 'readFile', wasmPath, { encoding: null }) const dataRead = new Uint8Array(buffer) const witness = await generate_witness(dataRead, input) // @ts-ignore diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index 9a5596c2f8..2522d94be7 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -201,15 +201,15 @@ class FileManager extends Plugin { * @param {string} data content to write on the file * @returns {void} */ - async writeFile(path, data, isBuffer?) { + async writeFile(path, data, options?) { try { path = this.normalize(path) path = this.limitPluginScope(path) if (await this.exists(path)) { await this._handleIsFile(path, `Cannot write file ${path}`) - return await this.setFileContent(path, data, isBuffer) + return await this.setFileContent(path, data, options) } else { - const ret = await this.setFileContent(path, data, isBuffer) + const ret = await this.setFileContent(path, data, options) this.emit('fileAdded', path) return ret } @@ -255,13 +255,13 @@ class FileManager extends Plugin { * @param {string} path path of the file * @returns {string} content of the file */ - async readFile(path, isBuffer?) { + async readFile(path, options?) { try { path = this.normalize(path) path = this.limitPluginScope(path) await this._handleExists(path, `Cannot read file ${path}`) await this._handleIsFile(path, `Cannot read file ${path}`) - return this.getFileContent(path, isBuffer) + return this.getFileContent(path, options) } catch (e) { throw new Error(e) } @@ -579,7 +579,7 @@ class FileManager extends Plugin { return path ? path[1] : '/' } - getFileContent(path, isBuffer?) { + getFileContent(path, options?) { const provider = this.fileProviderOf(path) if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) @@ -589,11 +589,11 @@ class FileManager extends Plugin { provider.get(path, (err, content) => { if (err) reject(err) resolve(content) - }, isBuffer) + }, options) }) } - async setFileContent(path, content, isBuffer?) { + async setFileContent(path, content, options?) { if (this.currentRequest) { const canCall = await this.askUserPermission(`writeFile`, `modifying ${path} ...`) const required = this.appManager.isRequired(this.currentRequest.from) @@ -602,10 +602,10 @@ class FileManager extends Plugin { this.call('notification', 'toast', fileChangedToastMsg(this.currentRequest.from, path)) } } - return await this._setFileInternal(path, content, isBuffer) + return await this._setFileInternal(path, content, options) } - _setFileInternal(path, content, isBuffer?) { + _setFileInternal(path, content, options?) { const provider = this.fileProviderOf(path) if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) // TODO : Add permission @@ -616,7 +616,7 @@ class FileManager extends Plugin { this.syncEditor(path) this.emit('fileSaved', path) resolve(true) - }, isBuffer) + }, options) }) } diff --git a/apps/remix-ide/src/app/files/fileProvider.js b/apps/remix-ide/src/app/files/fileProvider.js index f2c73d149d..432f6ad45c 100644 --- a/apps/remix-ide/src/app/files/fileProvider.js +++ b/apps/remix-ide/src/app/files/fileProvider.js @@ -87,12 +87,12 @@ class FileProvider { cb() } - async get (path, cb, isBuffer = false) { + async get (path, cb, options = { encoding: 'utf8' }) { cb = cb || function () { /* do nothing. */ } path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here var unprefixedpath = this.removePrefix(path) try { - const content = await window.remixFileSystem.readFile(unprefixedpath, isBuffer ? undefined : 'utf8') + const content = await window.remixFileSystem.readFile(unprefixedpath, options) if (cb) cb(null, content) return content } catch (err) { @@ -101,17 +101,17 @@ class FileProvider { } } - async set (path, content, cb, isBuffer = false) { + async set (path, content, cb, options = { encoding: 'utf8' }) { cb = cb || function () { /* do nothing. */ } var unprefixedpath = this.removePrefix(path) const exists = await window.remixFileSystem.exists(unprefixedpath) - if (exists && await window.remixFileSystem.readFile(unprefixedpath, isBuffer ? undefined : 'utf8') === content) { + if (exists && await window.remixFileSystem.readFile(unprefixedpath, options) === content) { if (cb) cb() return null } await this.createDir(path.substr(0, path.lastIndexOf('/'))) try { - await window.remixFileSystem.writeFile(unprefixedpath, content, isBuffer ? undefined : 'utf8') + await window.remixFileSystem.writeFile(unprefixedpath, content, options) } catch (e) { if (cb) cb(e) return false