Include encoding param

pull/4144/head
ioedeveloper 1 year ago
parent 5b9be5c1d5
commit 4e0d5f1641
  1. 4
      apps/circuit-compiler/src/app/services/circomPluginClient.ts
  2. 22
      apps/remix-ide/src/app/files/fileManager.ts
  3. 10
      apps/remix-ide/src/app/files/fileProvider.js

@ -143,7 +143,7 @@ export class CircomPluginClient extends PluginClient {
this.lastCompiledCircuitPath = extractParentFromKey(path) + "/.bin/" + fileName.replace('circom', 'wasm') this.lastCompiledCircuitPath = extractParentFromKey(path) + "/.bin/" + fileName.replace('circom', 'wasm')
// @ts-ignore // @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 fileContent = this.lastParsedFiles[path]
const searchComponentName = fileContent.match(/component\s+main\s*(?:{[^{}]*})?\s*=\s*([A-Za-z_]\w*)\s*\(.*\)/) 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') if (!wasmPath) throw new Error('No wasm file found')
// @ts-ignore // @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 dataRead = new Uint8Array(buffer)
const witness = await generate_witness(dataRead, input) const witness = await generate_witness(dataRead, input)
// @ts-ignore // @ts-ignore

@ -201,15 +201,15 @@ class FileManager extends Plugin {
* @param {string} data content to write on the file * @param {string} data content to write on the file
* @returns {void} * @returns {void}
*/ */
async writeFile(path, data, isBuffer?) { async writeFile(path, data, options?) {
try { try {
path = this.normalize(path) path = this.normalize(path)
path = this.limitPluginScope(path) path = this.limitPluginScope(path)
if (await this.exists(path)) { if (await this.exists(path)) {
await this._handleIsFile(path, `Cannot write file ${path}`) await this._handleIsFile(path, `Cannot write file ${path}`)
return await this.setFileContent(path, data, isBuffer) return await this.setFileContent(path, data, options)
} else { } else {
const ret = await this.setFileContent(path, data, isBuffer) const ret = await this.setFileContent(path, data, options)
this.emit('fileAdded', path) this.emit('fileAdded', path)
return ret return ret
} }
@ -255,13 +255,13 @@ class FileManager extends Plugin {
* @param {string} path path of the file * @param {string} path path of the file
* @returns {string} content of the file * @returns {string} content of the file
*/ */
async readFile(path, isBuffer?) { async readFile(path, options?) {
try { try {
path = this.normalize(path) path = this.normalize(path)
path = this.limitPluginScope(path) path = this.limitPluginScope(path)
await this._handleExists(path, `Cannot read file ${path}`) await this._handleExists(path, `Cannot read file ${path}`)
await this._handleIsFile(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) { } catch (e) {
throw new Error(e) throw new Error(e)
} }
@ -579,7 +579,7 @@ class FileManager extends Plugin {
return path ? path[1] : '/' return path ? path[1] : '/'
} }
getFileContent(path, isBuffer?) { getFileContent(path, options?) {
const provider = this.fileProviderOf(path) const provider = this.fileProviderOf(path)
if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` })
@ -589,11 +589,11 @@ class FileManager extends Plugin {
provider.get(path, (err, content) => { provider.get(path, (err, content) => {
if (err) reject(err) if (err) reject(err)
resolve(content) resolve(content)
}, isBuffer) }, options)
}) })
} }
async setFileContent(path, content, isBuffer?) { async setFileContent(path, content, options?) {
if (this.currentRequest) { if (this.currentRequest) {
const canCall = await this.askUserPermission(`writeFile`, `modifying ${path} ...`) const canCall = await this.askUserPermission(`writeFile`, `modifying ${path} ...`)
const required = this.appManager.isRequired(this.currentRequest.from) 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)) 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) const provider = this.fileProviderOf(path)
if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` }) if (!provider) throw createError({ code: 'ENOENT', message: `${path} not available` })
// TODO : Add permission // TODO : Add permission
@ -616,7 +616,7 @@ class FileManager extends Plugin {
this.syncEditor(path) this.syncEditor(path)
this.emit('fileSaved', path) this.emit('fileSaved', path)
resolve(true) resolve(true)
}, isBuffer) }, options)
}) })
} }

@ -87,12 +87,12 @@ class FileProvider {
cb() cb()
} }
async get (path, cb, isBuffer = false) { async get (path, cb, options = { encoding: 'utf8' }) {
cb = cb || function () { /* do nothing. */ } cb = cb || function () { /* do nothing. */ }
path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here path = this.getPathFromUrl(path) || path // ensure we actually use the normalized path from here
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
try { try {
const content = await window.remixFileSystem.readFile(unprefixedpath, isBuffer ? undefined : 'utf8') const content = await window.remixFileSystem.readFile(unprefixedpath, options)
if (cb) cb(null, content) if (cb) cb(null, content)
return content return content
} catch (err) { } 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. */ } cb = cb || function () { /* do nothing. */ }
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
const exists = await window.remixFileSystem.exists(unprefixedpath) 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() if (cb) cb()
return null return null
} }
await this.createDir(path.substr(0, path.lastIndexOf('/'))) await this.createDir(path.substr(0, path.lastIndexOf('/')))
try { try {
await window.remixFileSystem.writeFile(unprefixedpath, content, isBuffer ? undefined : 'utf8') await window.remixFileSystem.writeFile(unprefixedpath, content, options)
} catch (e) { } catch (e) {
if (cb) cb(e) if (cb) cb(e)
return false return false

Loading…
Cancel
Save