Space Cat, Prince Among Thieves

Read Browser File Inputs with Go WebAssembly

I have been playing with WebAssembly since Go added support for it in 2017.

For a very long time now, I've been wanting to be able to accept files from an end user and process them with Go on their local machine. Basically I just want to read files from file inputs. I knew it had to be possible, but could not in all this time find a good walkthrough online. A couple nights ago I set my mind to it and figured it out.

Essentially we need to execute the following JavaScript, but in Go via the JS syscall API.

So after transliterating that JavaScript into Go syscall/js calls, we then using js.CopyBytesToGo to pass the given Uint8Array back to our WASM runtime where we can do with the bytes as we please.

Note, given the keyword any here, this example requires Go 1.18 - the syscall/js library is still considered experimental and expect it to break on major go releases.

This is as written for brevity and could be improved in code safety in a number of pretty obvious ways.

The iframe below runs the compiled WASM and spits out any file you upload to it, via Go.


Read More / Comment »

Use a GIF as a Zoom Virtual Background

Update August 17 2021: I've got the tool working in Chrome and Firefox by launching it a standalone new window instead of loading in an iframe. It is still broken in Safari for unknown reasons. It's not ideal, but until the whole SharedArrayBuffer debacle settles down, it's probably the best I can …

Read More / Comment »

Recent Comments

Great Tool!

Very nice tool helps me to build m'y alien vehicle

Thank you so much I needed to know how to make a big circle in minecraft, I am trying to make the clock map in hunger games

Would it be possible to export this to a google sheet / excel, for like planning and whatnot?

Helped me lay out my 55*33 arena! Thanks a lot