@@ -1365,8 +1365,8 @@ static JSValue js_std_file_getline(JSContext *ctx, JSValue this_val,
13651365}
13661366
13671367/* XXX: could use less memory and go faster */
1368- static JSValue js_std_file_readAsString (JSContext * ctx , JSValue this_val ,
1369- int argc , JSValue * argv )
1368+ static JSValue js_std_file_readAs (JSContext * ctx , JSValue this_val ,
1369+ int argc , JSValue * argv , int magic )
13701370{
13711371 FILE * f = js_std_file_get (ctx , this_val );
13721372 int c ;
@@ -1402,7 +1402,11 @@ static JSValue js_std_file_readAsString(JSContext *ctx, JSValue this_val,
14021402 }
14031403 max_size -- ;
14041404 }
1405- obj = JS_NewStringLen (ctx , (const char * )dbuf .buf , dbuf .size );
1405+ if (magic ) {
1406+ obj = JS_NewStringLen (ctx , (const char * )dbuf .buf , dbuf .size );
1407+ } else {
1408+ obj = JS_NewArrayBufferCopy (ctx , dbuf .buf , dbuf .size );
1409+ }
14061410 dbuf_free (& dbuf );
14071411 return obj ;
14081412}
@@ -1694,7 +1698,8 @@ static const JSCFunctionListEntry js_std_file_proto_funcs[] = {
16941698 JS_CFUNC_MAGIC_DEF ("read" , 3 , js_std_file_read_write , 0 ),
16951699 JS_CFUNC_MAGIC_DEF ("write" , 3 , js_std_file_read_write , 1 ),
16961700 JS_CFUNC_DEF ("getline" , 0 , js_std_file_getline ),
1697- JS_CFUNC_DEF ("readAsString" , 0 , js_std_file_readAsString ),
1701+ JS_CFUNC_MAGIC_DEF ("readAsArrayBuffer" , 0 , js_std_file_readAs , 0 ),
1702+ JS_CFUNC_MAGIC_DEF ("readAsString" , 0 , js_std_file_readAs , 1 ),
16981703 JS_CFUNC_DEF ("getByte" , 0 , js_std_file_getByte ),
16991704 JS_CFUNC_DEF ("putByte" , 1 , js_std_file_putByte ),
17001705 /* setvbuf, ... */
0 commit comments