@@ -61,14 +61,10 @@ static void free_fetch_context(FetchContext* ctx) {
6161#if defined(__EMSCRIPTEN__ )
6262static void fetch_with_emscripten_success (emscripten_fetch_t * fetch ) {
6363 FetchContext * ctx = (FetchContext * )fetch -> userData ;
64-
6564 int http_status = fetch -> status ;
66- printf ("Kinetoscope: url = %s, http status = %d\n" , ctx -> url , http_status );
67-
6865 bool ok = http_status == 200 || http_status == 206 ;
69- if (ok ) {
70- ctx -> write_callback ((char * )fetch -> data , fetch -> numBytes , 1 , ctx -> user_ctx );
71- }
66+
67+ printf ("Kinetoscope: url = %s, http status = %d\n" , ctx -> url , http_status );
7268
7369 if (ctx -> done_callback ) {
7470 ctx -> done_callback (ok , ctx -> user_ctx );
@@ -78,6 +74,16 @@ static void fetch_with_emscripten_success(emscripten_fetch_t* fetch) {
7874 emscripten_fetch_close (fetch );
7975}
8076
77+ static void fetch_with_emscripten_progress (emscripten_fetch_t * fetch ) {
78+ FetchContext * ctx = (FetchContext * )fetch -> userData ;
79+ int http_status = fetch -> status ;
80+ bool ok = http_status == 200 || http_status == 206 ;
81+
82+ if (ok ) {
83+ ctx -> write_callback ((char * )fetch -> data , fetch -> numBytes , 1 , ctx -> user_ctx );
84+ }
85+ }
86+
8187static void fetch_with_emscripten_error (emscripten_fetch_t * fetch ) {
8288 FetchContext * ctx = (FetchContext * )fetch -> userData ;
8389
@@ -163,7 +169,7 @@ static void fetch_range_async(const char* url, size_t first_byte, size_t size,
163169 emscripten_fetch_attr_init (& fetch_attributes );
164170
165171 strcpy (fetch_attributes .requestMethod , "GET" );
166- fetch_attributes .attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY ;
172+ fetch_attributes .attributes = EMSCRIPTEN_FETCH_STREAM_DATA ;
167173
168174 if (ctx -> range ) {
169175 const char * * headers = malloc (sizeof (char * ) * 3 );
@@ -178,6 +184,7 @@ static void fetch_range_async(const char* url, size_t first_byte, size_t size,
178184
179185 fetch_attributes .userData = ctx ;
180186 fetch_attributes .onsuccess = fetch_with_emscripten_success ;
187+ fetch_attributes .onprogress = fetch_with_emscripten_progress ;
181188 fetch_attributes .onerror = fetch_with_emscripten_error ;
182189
183190 emscripten_fetch (& fetch_attributes , url );
0 commit comments