14 # include <emscripten/fetch.h>
21 assert(pthread_self() != 0 &&
"Fetching is not allowed on the main thread");
23 emscripten_fetch_attr_t attr;
24 emscripten_fetch_attr_init(&attr);
25 std::strcpy(attr.requestMethod,
"HEAD");
26 attr.attributes = EMSCRIPTEN_FETCH_SYNCHRONOUS;
27 emscripten_fetch_t* fetch = emscripten_fetch(&attr, url.c_str());
28 bool exists = fetch->status == 200;
29 emscripten_fetch_close(fetch);
37 assert(pthread_self() != 0 &&
"Fetching is not allowed on the main thread");
39 std::cout <<
"FETCH \"" << url <<
"\"" << std::endl;
41 emscripten_fetch_attr_t attr;
42 emscripten_fetch_attr_init(&attr);
43 std::strcpy(attr.requestMethod,
"GET");
44 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_SYNCHRONOUS;
45 emscripten_fetch_t* fetch = emscripten_fetch(&attr, url.c_str());
47 int status = fetch->status;
48 size_t size = (size_t)fetch->totalBytes;
49 std::cout <<
"STATUS: " << status <<
", SIZE: " <<
size << std::endl;
56 emscripten_fetch_close(fetch);
SLIOReaderFetch(std::string url)
static bool exists(std::string url)
SLIOStream implementation for reading from memory.
void set(std::string path, const std::vector< char > &data)
void clear(std::string path)