added 9pfs.create_file_from_url()
This commit is contained in:
parent
c97875e3e5
commit
c207b2da2a
5 changed files with 31 additions and 19 deletions
|
|
@ -439,9 +439,10 @@ if( typeof AFRAME != 'undefined '){
|
||||||
this.el.addEventListener('exec', (e) => this.term.exec( e.detail ) )
|
this.el.addEventListener('exec', (e) => this.term.exec( e.detail ) )
|
||||||
this.el.addEventListener('hook', (e) => this.term.hook( e.detail[0], e.detail[1] ) )
|
this.el.addEventListener('hook', (e) => this.term.hook( e.detail[0], e.detail[1] ) )
|
||||||
this.el.addEventListener('send', (e) => this.term.send( e.detail[0], e.detail[1] || 0 ) )
|
this.el.addEventListener('send', (e) => this.term.send( e.detail[0], e.detail[1] || 0 ) )
|
||||||
this.el.addEventListener('create_file', async (e) => await this.term.worker.create_file( e.detail[0], this.term.convert.toUint8Array(e.detail[1]) ) )
|
this.el.addEventListener('create_file', async (e) => await this.term.worker.create_file( e.detail[0], e.detail[1] ) )
|
||||||
this.el.addEventListener('update_file', async (e) => await this.term.worker.update_file( e.detail[0], this.term.convert.toUint8Array(e.detail[1]) ) )
|
this.el.addEventListener('create_file_from_url', async (e) => await this.term.worker.create_file_from_url( e.detail[0], e.detail[1] ) )
|
||||||
this.el.addEventListener('append_file', async (e) => await this.term.worker.append_file( e.detail[0], this.term.convert.toUint8Array(e.detail[1]) ) )
|
this.el.addEventListener('update_file', async (e) => await this.term.worker.update_file( e.detail[0], e.detail[1] ) )
|
||||||
|
this.el.addEventListener('append_file', async (e) => await this.term.worker.append_file( e.detail[0], e.detail[1] ) )
|
||||||
this.el.addEventListener('read_file', async (e) => {
|
this.el.addEventListener('read_file', async (e) => {
|
||||||
const buf = await this.term.worker.read_file( e.detail[0] )
|
const buf = await this.term.worker.read_file( e.detail[0] )
|
||||||
const str = new TextDecoder().decode(buf)
|
const str = new TextDecoder().decode(buf)
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,14 @@ function ISOTerminal(instance,opts){
|
||||||
|
|
||||||
ISOTerminal.prototype.emit = function(event,data,sender){
|
ISOTerminal.prototype.emit = function(event,data,sender){
|
||||||
data = data || false
|
data = data || false
|
||||||
|
// *TODO* wrap certain events into this.preventFrameDrop( () => { .. }) to boost performance
|
||||||
const evObj = new CustomEvent(event, {detail: data} )
|
const evObj = new CustomEvent(event, {detail: data} )
|
||||||
this.preventFrameDrop( () => {
|
// forward event to worker/instance/AFRAME element or component-function
|
||||||
// forward event to worker/instance/AFRAME element or component-function
|
// this feels complex, but actually keeps event- and function-names more concise in codebase
|
||||||
// this feels complex, but actually keeps event- and function-names more concise in codebase
|
this.dispatchEvent( evObj )
|
||||||
this.dispatchEvent( evObj )
|
if( sender != "instance" && this.instance ) this.instance.dispatchEvent(evObj)
|
||||||
if( sender != "instance" && this.instance ) this.instance.dispatchEvent(evObj)
|
if( sender != "worker" && this.worker ) this.worker.postMessage({event,data}, PromiseWorker.prototype.getTransferable(data) )
|
||||||
if( sender != "worker" && this.worker ) this.worker.postMessage({event,data}, PromiseWorker.prototype.getTransferable(data) )
|
if( sender !== undefined && typeof this[event] == 'function' ) this[event].apply(this, data && data.push ? data : [data] )
|
||||||
if( sender !== undefined && typeof this[event] == 'function' ) this[event].apply(this, data && data.push ? data : [data] )
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ISOTerminal.addEventListener = (event,cb) => {
|
ISOTerminal.addEventListener = (event,cb) => {
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,8 @@ function PromiseWorker(file, onmessage){
|
||||||
this.resolvers = this.resolvers || {last:1,pending:{}}
|
this.resolvers = this.resolvers || {last:1,pending:{}}
|
||||||
msg.data.promiseId = this.resolvers.last++
|
msg.data.promiseId = this.resolvers.last++
|
||||||
// Send id and task to WebWorker
|
// Send id and task to WebWorker
|
||||||
worker.postMessage(msg, PromiseWorker.prototype.getTransferable(msg.data) )
|
let dataTransferable = PromiseWorker.prototype.getTransferable(msg.data)
|
||||||
|
worker.postMessage(msg, dataTransferable )
|
||||||
return new Promise( resolve => this.resolvers.pending[ msg.data.promiseId ] = resolve );
|
return new Promise( resolve => this.resolvers.pending[ msg.data.promiseId ] = resolve );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -72,6 +73,5 @@ PromiseWorker.prototype.getTransferable = function(data){
|
||||||
for( var i in data ){
|
for( var i in data ){
|
||||||
if( isTransferable(data[i]) ) objs.push(data[i])
|
if( isTransferable(data[i]) ) objs.push(data[i])
|
||||||
}
|
}
|
||||||
if( objs.length ) debugger
|
|
||||||
return objs.length ? objs : undefined
|
return objs.length ? objs : undefined
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,17 @@ emulator.fs9p.update_file = async function(file,data){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emulator.fs9p.create_file_from_url = async function(file,url){
|
||||||
|
const convert = ISOTerminal.prototype.convert
|
||||||
|
return fetch(url)
|
||||||
|
.then( (res) => res.arrayBuffer() )
|
||||||
|
.then( (buf) => {
|
||||||
|
let arr = new Uint8Array(buf)
|
||||||
|
return emulator.create_file(file, arr )
|
||||||
|
})
|
||||||
|
.catch( console.error )
|
||||||
|
}
|
||||||
|
|
||||||
emulator.fs9p.append_file = async function(file,data){
|
emulator.fs9p.append_file = async function(file,data){
|
||||||
const convert = ISOTerminal.prototype.convert
|
const convert = ISOTerminal.prototype.convert
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ importScripts("ISOTerminal.js") // we don't instance it again here (just use it
|
||||||
|
|
||||||
this.runISO = async function(opts){
|
this.runISO = async function(opts){
|
||||||
this.opts = opts
|
this.opts = opts
|
||||||
if( opts.debug ) console.dir(opts)
|
if( opts.debug ) console.dir(opts)
|
||||||
|
|
||||||
if( opts.cdrom && !opts.cdrom.url.match(/^http/) ) opts.cdrom.url = "../../"+opts.cdrom.url
|
if( opts.cdrom && !opts.cdrom.url.match(/^http/) ) opts.cdrom.url = "../../"+opts.cdrom.url
|
||||||
if( opts.bzimage && !opts.cdrom.url.match(/^http/) ) opts.bzimage.url = "../../"+opts.bzimage.url
|
if( opts.bzimage && !opts.cdrom.url.match(/^http/) ) opts.bzimage.url = "../../"+opts.bzimage.url
|
||||||
|
|
@ -52,11 +52,12 @@ this.runISO = async function(opts){
|
||||||
arr[0] = String(arr[0]).replace(/^\/mnt/,'')
|
arr[0] = String(arr[0]).replace(/^\/mnt/,'')
|
||||||
return arr
|
return arr
|
||||||
}
|
}
|
||||||
this.create_file = async function(){ return emulator.create_file.apply(emulator, stripMountDir(arguments[0]) ) }
|
this.create_file = async function(){ return emulator.create_file.apply(emulator, stripMountDir(arguments[0]) ) }
|
||||||
this.read_file = async function(){ return emulator.read_file.apply(emulator, stripMountDir(arguments[0]) ) }
|
this.create_file_from_url = async function(){ return emulator.fs9p.create_file_from_url.apply(emulator, stripMountDir(arguments[0]) ) }
|
||||||
this.read_file_world = async function(){ return emulator.fs9p.read_file_world.apply(emulator.fs9p, stripMountDir(arguments[0]) ) }
|
this.read_file = async function(){ return emulator.read_file.apply(emulator, stripMountDir(arguments[0]) ) }
|
||||||
this.append_file = async function(){ emulator.fs9p.append_file.apply(emulator.fs9p, stripMountDir(arguments[0])) }
|
this.read_file_world = async function(){ return emulator.fs9p.read_file_world.apply(emulator.fs9p, stripMountDir(arguments[0]) ) }
|
||||||
this.update_file = async function(){ emulator.fs9p.update_file.apply(emulator.fs9p, stripMountDir(arguments[0])) }
|
this.append_file = async function(){ emulator.fs9p.append_file.apply(emulator.fs9p, stripMountDir(arguments[0])) }
|
||||||
|
this.update_file = async function(){ emulator.fs9p.update_file.apply(emulator.fs9p, stripMountDir(arguments[0])) }
|
||||||
|
|
||||||
// filename will be read from 9pfs: "/mnt/"+filename
|
// filename will be read from 9pfs: "/mnt/"+filename
|
||||||
emulator.readFromPipe = function(filename,cb){
|
emulator.readFromPipe = function(filename,cb){
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue