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

Function main

test/fetch/test_fetch_cached_xhr.cpp:39–70  ·  view source on GitHub ↗

XHR and store to cache.

Source from the content-addressed store, hash-verified

37
38// XHR and store to cache.
39int 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}

Callers

nothing calls this directly

Calls 9

strcpyFunction · 0.85
printfFunction · 0.85
emscripten_fetch_closeFunction · 0.85
fetchFromIndexedDBFunction · 0.85
emscripten_fetchFunction · 0.85
memsetFunction · 0.85
assertFunction · 0.50
abortFunction · 0.50

Tested by

no test coverage detected