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')
// @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

@ -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)
})
}

@ -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

Loading…
Cancel
Save