File tree Expand file tree Collapse file tree 2 files changed +2
-25
lines changed
Expand file tree Collapse file tree 2 files changed +2
-25
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ function getWorkerScript(file: string): string {
2323 onmessage: function () {},
2424 DecompressionStream,
2525 CompressionStream,
26+ Response,
2627 };
2728
2829 vm.runInNewContext(scriptContent, sandbox, { filename: "${ file } " });
Original file line number Diff line number Diff line change 33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
55async function readableStreamToBuffer ( stream ) {
6- const reader = stream . getReader ( ) ;
7- const chunks = [ ] ;
8-
9- try {
10- while ( true ) {
11- const { done, value } = await reader . read ( ) ;
12- if ( done ) break ;
13- if ( value ) {
14- chunks . push ( value ) ;
15- }
16- }
17- } finally {
18- reader . releaseLock ( ) ;
19- }
20-
21- // Calculate total length and combine chunks
22- const totalLength = chunks . reduce ( ( sum , chunk ) => sum + chunk . length , 0 ) ;
23- const result = new Uint8Array ( totalLength ) ;
24- let offset = 0 ;
25- for ( const chunk of chunks ) {
26- result . set ( chunk , offset ) ;
27- offset += chunk . length ;
28- }
29-
30- return result ;
6+ return new Uint8Array ( await new Response ( stream ) . arrayBuffer ( ) ) ;
317}
328
339onmessage = async ( e ) => {
You can’t perform that action at this time.
0 commit comments