MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / fetchFromIndexedDB

Function fetchFromIndexedDB

test/fetch/test_fetch_cached_xhr.cpp:16–36  ·  view source on GitHub ↗

Fetch file without XHRing.

Source from the content-addressed store, hash-verified

14
15// Fetch file without XHRing.
16void 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.
39int main() {

Callers 1

mainFunction · 0.85

Calls 7

strcpyFunction · 0.85
printfFunction · 0.85
emscripten_fetch_closeFunction · 0.85
emscripten_fetchFunction · 0.85
assertFunction · 0.50
exitFunction · 0.50

Tested by

no test coverage detected