Ok, I made my own implementation of this function and sent a pull 
request https://github.com/kripken/emscripten/pull/2180

On Monday, March 3, 2014 10:39:23 AM UTC-8, Alon Zakai wrote:
>
> Pull request would be welcome.
>
> - Alon
>
>
>
> On Mon, Mar 3, 2014 at 5:16 AM, Rob Raguet-Schofield 
> <[email protected]<javascript:>
> > wrote:
>
>> I also needed this functionality, but I was unable to make it work with 
>> the built-in functions.  I added my own modified version of this function. 
>>  Here's the JS implementation:
>>
>>
>> mergeInto(LibraryManager.library, {
>>         IOJSURLRequest : function(url, method, param, arg, onload, 
>> onerror, onprogress) {
>>                 var _url = Pointer_stringify(url);
>>                 var _method = Pointer_stringify(method);
>>                 var _param = Pointer_stringify(param);
>>
>>                 var http = new XMLHttpRequest();
>>                 http.open(_method, _url, true);
>>                 http.responseType = 'arraybuffer';
>>
>>                 http.onload = function(e) {
>>                         if (http.status == 200) {
>>                                 if (onload) {
>>                                         var byteArray = new 
>> Uint8Array(http.response);
>>                                         var buffer = 
>> _malloc(byteArray.length);
>>                                         HEAPU8.set(byteArray, buffer);
>>                                         Runtime.dynCall('viii', onload, 
>> [arg, buffer, byteArray.length]);
>>                                         _free(buffer);
>>                                 }
>>                         } else {
>>                                 if (onerror) Runtime.dynCall('vii', 
>> onerror, [arg, http.status]);
>>                         }
>>                 };
>>                 http.onerror = function(e) {
>>                         if (onerror) Runtime.dynCall('vii', onerror, 
>> [arg, http.status]);
>>                 };
>>                 http.onprogress = function(e) {
>>                         var percentComplete = (e.position / 
>> e.totalSize)*100;
>>                         if (onprogress) Runtime.dynCall('vii', 
>> onprogress, [arg, percentComplete]);
>>                 };
>>
>>                 if (_method == "POST") {
>>                         http.setRequestHeader("Content-type", 
>> "application/x-www-form-urlencoded");
>>                         http.send(_param);
>>                 } else {
>>                         http.send(null);
>>                 }
>>         }
>> });
>>
>>
>> Then you can call the function from C/C++:
>>
>>
>> extern "C" void IOJSURLRequest(const char* url,  const char* method, 
>> const char* param, void* context, void (*onload)(void* context, const void* 
>> data, int len), void (*onerror)(void* context, int error), void 
>> (*onprogress)(void* context, int progress));
>>
>>
>> And build with --js-library foo.js
>>
>>
>>
>> On Mar 2, 2014, at 11:09 PM, Joel Croteau <[email protected]<javascript:>> 
>> wrote:
>> > I would like to be able to load a file from a URL directly into memory, 
>> while having the functionality of emscripten_async_wget2. Would it be 
>> possible to have this implemented?
>>
>>
>> Rob Raguet-Schofield
>> (rob ra gA skO fEld)
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to