MCPcopy Create free account
hub / github.com/firebase/firebase-tools / downloadFile

Function downloadFile

scripts/emulator-tests/unzipEmulators.spec.ts:79–115  ·  view source on GitHub ↗
(url: string, targetPath: string)

Source from the content-addressed store, hash-verified

77});
78
79async function downloadFile(url: string, targetPath: string): Promise<string> {
80 const u = new URL(url);
81 const c = new Client({ urlPrefix: u.origin, auth: false });
82
83 const writeStream = fs.createWriteStream(targetPath);
84
85 const res = await c.request<void, NodeJS.ReadableStream>({
86 method: "GET",
87 path: u.pathname,
88 queryParams: u.searchParams,
89 responseType: "stream",
90 resolveOnHTTPError: true,
91 });
92
93 if (res.status !== 200) {
94 throw new Error(
95 `Download failed, file "${url}" does not exist. status ${
96 res.status
97 }: ${await res.response.text()}`,
98 {
99 cause: new Error(
100 `Object returned by getDownloadDetails() from src${path.sep}emulator${path.sep}downloadableEmulators.ts contains invalid URL: ${url}`,
101 ),
102 },
103 );
104 }
105
106 return new Promise<string>((resolve, reject) => {
107 writeStream.on("finish", () => {
108 resolve(targetPath);
109 });
110 writeStream.on("error", (err) => {
111 reject(err);
112 });
113 res.body.pipe(writeStream);
114 });
115}

Callers 1

Calls 3

resolveFunction · 0.85
onMethod · 0.80
rejectFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…