In JavaScript, I'd like to load a pod resource into an InStream or a Buf. In plain Fantom I use this:
(`fan://wotever/res/wotever.bin`.get as File).in
But, assuming pod resources are being served up, how would I accomplish the same in JavaScript?
Fingers Crossed it's possible* *
Steve.
andyWed 25 Jul 2012
You have have to manually handle that yourself. Images work because all we do is set the <img src=xxx/> and the browser handles requesting the resource.
In your case - you will have to open up a HttpReq yourself to fetch the data. Also keep in mind the response is asynchronous - so won't block while waiting for request to finish.
SlimerDudeWed 25 Jul 2012
Sadly it seems binary data and javascript do not go hand in hand. :(
There are a couple of various tweaks out there, e.g. This jQuery Binary Ajax downloads a binary file as a String, and jDataView: Read Binary File then acts like a sys::Buf. But it seems a little overkill, and complex to merge into Fantom.
The HTML 5 File API looks promising but is geared towards local files... and is HTML 5.
As all I want is static data, I'll look into auto-generating some JavaScript which statically pushes data into a Buf.
SlimerDude Wed 25 Jul 2012
In JavaScript, I'd like to load a pod resource into an InStream or a Buf. In plain Fantom I use this:
But, assuming pod resources are being served up, how would I accomplish the same in JavaScript?
Fingers Crossed it's possible* *
Steve.
andy Wed 25 Jul 2012
You have have to manually handle that yourself. Images work because all we do is set the
<img src=xxx/>
and the browser handles requesting the resource.In your case - you will have to open up a HttpReq yourself to fetch the data. Also keep in mind the response is asynchronous - so won't block while waiting for request to finish.
SlimerDude Wed 25 Jul 2012
Sadly it seems binary data and javascript do not go hand in hand. :(
There are a couple of various tweaks out there, e.g. This jQuery Binary Ajax downloads a binary file as a String, and jDataView: Read Binary File then acts like a
sys::Buf
. But it seems a little overkill, and complex to merge into Fantom.The HTML 5 File API looks promising but is geared towards local files... and is HTML 5.
As all I want is static data, I'll look into auto-generating some JavaScript which statically pushes data into a Buf.
Sigh