(url, outputPath, ctxId)
| 113 | } |
| 114 | |
| 115 | var web_req_sync_download = function (url, outputPath, ctxId) { |
| 116 | create_web_ctx_if_needed(ctxId); |
| 117 | var urlCpy = url; |
| 118 | url = web_req_build_url(url, ctxId); |
| 119 | |
| 120 | var req = new XMLHttpRequest(); |
| 121 | req.open(web_req_ctxs[ctxId].method, url, false); |
| 122 | // Preserve raw byte values in responseText for binary reconstruction via FS.writeFile; |
| 123 | // this older pattern is kept here for maximum sync-XHR compatibility across browsers. |
| 124 | req.overrideMimeType("text/plain; charset=x-user-defined"); |
| 125 | for (var i = 0; i < web_req_ctxs[ctxId].headers.length; i++) { |
| 126 | req.setRequestHeader(web_req_ctxs[ctxId].headers[i].key, web_req_ctxs[ctxId].headers[i].value); |
| 127 | } |
| 128 | |
| 129 | req.send(web_req_get_payload(ctxId)); |
| 130 | |
| 131 | if (req.status >= 200 && req.status < 300) { |
| 132 | FS.writeFile(outputPath, str_to_bytearray(req.responseText || "")); |
| 133 | if (web_req_ctxs[ctxId].use_download_callback) { |
| 134 | Module.ccall('emsCallDownloadCallback', 'number', ['number', 'number'], [1, ctxId]); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | var res = { |
| 139 | url: urlCpy, |
| 140 | code: req.status, |
| 141 | text: "", |
| 142 | error: (req.status < 200 || req.status > 399) ? req.statusText : null |
| 143 | }; |
| 144 | Module.ccall('emsCallResponseCallback', 'number', ['string', 'bool', 'number'], [JSON.stringify(res), false, ctxId]); |
| 145 | } |
| 146 | |
| 147 | var web_req_async_download = function (url, outputPath, ctxId) { |
| 148 | create_web_ctx_if_needed(ctxId); |
no test coverage detected