@@ -9,6 +9,8 @@ https://github.com/curiousdannii/asyncglk
99
1010*/
1111
12+ import { gunzipSync } from 'fflate'
13+
1214export type ProgressCallback = ( bytes : number ) => void
1315
1416export type TruthyOption = boolean | number
@@ -48,14 +50,19 @@ export async function fetch_resource(options: DownloadOptions, path: string, pro
4850async function fetch_resource_inner ( options : DownloadOptions , path : string , progress_callback ?: ProgressCallback ) {
4951 // Handle embedded resources in single file mode
5052 if ( options . single_file ) {
51- const data = ( document . getElementById ( path ) as HTMLScriptElement ) . text
53+ const node = document . getElementById ( path ) as HTMLScriptElement
54+ const data_base64 = node . text
5255 if ( path . endsWith ( '.js' ) ) {
53- return import ( `data:text/javascript,${ encodeURIComponent ( data ) } ` )
56+ return import ( `data:text/javascript,${ encodeURIComponent ( data_base64 ) } ` )
5457 }
5558 if ( ! path . endsWith ( '.wasm' ) ) {
5659 throw new Error ( `Can't load ${ path } in single file mode` )
5760 }
58- return parse_base64 ( data )
61+ let data = await parse_base64 ( data_base64 )
62+ if ( node . type . endsWith ( ';gzip' ) ) {
63+ data = gunzipSync ( data )
64+ }
65+ return data
5966 }
6067
6168 // Handle when lib_path is a proper URL (such as import.meta.url), as well as the old style path fragment
0 commit comments