Fetch file without XHRing.
| 14 | |
| 15 | // Fetch file without XHRing. |
| 16 | void fetchFromIndexedDB() { |
| 17 | emscripten_fetch_attr_t attr; |
| 18 | emscripten_fetch_attr_init(&attr); |
| 19 | strcpy(attr.requestMethod, "GET"); |
| 20 | attr.onsuccess = [](emscripten_fetch_t *fetch) { |
| 21 | assert(fetch->numBytes == fetch->totalBytes); |
| 22 | assert(fetch->data != 0); |
| 23 | printf("Finished downloading %llu bytes\n", fetch->numBytes); |
| 24 | emscripten_fetch_close(fetch); |
| 25 | exit(0); |
| 26 | }; |
| 27 | attr.onprogress = [](emscripten_fetch_t *fetch) { |
| 28 | if (fetch->totalBytes > 0) { |
| 29 | printf("Downloading.. %.2f%% complete.\n", (fetch->dataOffset + fetch->numBytes) * 100.0 / fetch->totalBytes); |
| 30 | } else { |
| 31 | printf("Downloading.. %lld bytes complete.\n", fetch->dataOffset + fetch->numBytes); |
| 32 | } |
| 33 | }; |
| 34 | attr.attributes = EMSCRIPTEN_FETCH_APPEND | EMSCRIPTEN_FETCH_NO_DOWNLOAD; |
| 35 | emscripten_fetch_t *fetch = emscripten_fetch(&attr, "gears.png"); |
| 36 | } |
| 37 | |
| 38 | // XHR and store to cache. |
| 39 | int main() { |
no test coverage detected