XHR and store to cache.
| 37 | |
| 38 | // XHR and store to cache. |
| 39 | int main() { |
| 40 | emscripten_fetch_attr_t attr; |
| 41 | emscripten_fetch_attr_init(&attr); |
| 42 | strcpy(attr.requestMethod, "GET"); |
| 43 | attr.onsuccess = [](emscripten_fetch_t *fetch) { |
| 44 | assert(fetch->numBytes == fetch->totalBytes); |
| 45 | assert(fetch->data != 0); |
| 46 | printf("Finished downloading %llu bytes\n", fetch->numBytes); |
| 47 | emscripten_fetch_close(fetch); |
| 48 | |
| 49 | // Test that the file now exists: |
| 50 | fetchFromIndexedDB(); |
| 51 | }; |
| 52 | attr.onerror = [](emscripten_fetch_t *fetch) { |
| 53 | printf("Error downloading\n"); |
| 54 | abort(); |
| 55 | }; |
| 56 | attr.onprogress = [](emscripten_fetch_t *fetch) { |
| 57 | if (fetch->totalBytes > 0) { |
| 58 | printf("Downloading.. %.2f%% complete.\n", (fetch->dataOffset + fetch->numBytes) * 100.0 / fetch->totalBytes); |
| 59 | } else { |
| 60 | printf("Downloading.. %lld bytes complete.\n", fetch->dataOffset + fetch->numBytes); |
| 61 | } |
| 62 | }; |
| 63 | attr.attributes = EMSCRIPTEN_FETCH_REPLACE | EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_PERSIST_FILE; |
| 64 | emscripten_fetch_t *fetch = emscripten_fetch(&attr, "gears.png"); |
| 65 | assert(fetch != 0); |
| 66 | // emscripten_fetch() must be able to operate without referencing to this |
| 67 | // structure after the call. |
| 68 | memset(&attr, 0, sizeof(attr)); |
| 69 | return 99; |
| 70 | } |
nothing calls this directly
no test coverage detected