|
1 | 1 | import type * as types from "../shared/types"
|
2 | 2 | import * as common from "../shared/common"
|
3 | 3 | import * as ourselves from "./mod"
|
4 |
| -import * as denoflate from "https://deno.land/x/[email protected]/mod.ts" |
5 | 4 |
|
6 | 5 | declare const ESBUILD_VERSION: string
|
7 | 6 |
|
@@ -70,7 +69,7 @@ async function installFromNPM(name: string, subpath: string): Promise<string> {
|
70 | 69 | const npmRegistry = Deno.env.get("NPM_CONFIG_REGISTRY") || "https://registry.npmjs.org"
|
71 | 70 | const url = `${npmRegistry}/${name}/-/${name.replace("@esbuild/", "")}-${version}.tgz`
|
72 | 71 | const buffer = await fetch(url).then(r => r.arrayBuffer())
|
73 |
| - const executable = extractFileFromTarGzip(new Uint8Array(buffer), subpath) |
| 72 | + const executable = await extractFileFromTarGzip(new Uint8Array(buffer), subpath) |
74 | 73 |
|
75 | 74 | await Deno.mkdir(finalDir, {
|
76 | 75 | recursive: true,
|
@@ -117,9 +116,29 @@ function getCachePath(name: string): { finalPath: string, finalDir: string } {
|
117 | 116 | return { finalPath, finalDir }
|
118 | 117 | }
|
119 | 118 |
|
120 |
| -function extractFileFromTarGzip(buffer: Uint8Array, file: string): Uint8Array { |
| 119 | +async function gunzip(data: Uint8Array): Promise<Uint8Array> { |
| 120 | + const stream = new DecompressionStream('gzip'); |
| 121 | + const writer = stream.writable.getWriter(); |
| 122 | + const reader = stream.readable.getReader(); |
| 123 | + writer.write(data); |
| 124 | + writer.close(); |
| 125 | + const chunks: Uint8Array[] = []; |
| 126 | + while (true) { |
| 127 | + const { value, done } = await reader.read(); |
| 128 | + if (done) break; |
| 129 | + chunks.push(value); |
| 130 | + } |
| 131 | + const result = new Uint8Array(chunks.reduce((sum, chunk) => sum + chunk.length, 0)); |
| 132 | + for (let i = 0, offset = 0; i < chunks.length; i++) { |
| 133 | + result.set(chunks[i], offset); |
| 134 | + offset += chunks[i].length; |
| 135 | + } |
| 136 | + return result; |
| 137 | +} |
| 138 | + |
| 139 | +async function extractFileFromTarGzip(buffer: Uint8Array, file: string): Promise<Uint8Array> { |
121 | 140 | try {
|
122 |
| - buffer = denoflate.gunzip(buffer) |
| 141 | + buffer = await gunzip(buffer) |
123 | 142 | } catch (err: any) {
|
124 | 143 | throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`)
|
125 | 144 | }
|
|
0 commit comments