stream update zip to disk
Massimo Melina committed
Dec 13, 2025 at 01:03 UTC
91ccec4b2fd0b11347df07984eeb48a2b40f90a7
1 file changed
+9
-5
src/update.ts
+9
-5
@@ -4,7 +4,7 @@ import { apiGithubPaginated, getProjectInfo, getRepoInfo } from './github'
4
import { ARGS_FILE, HFS_REPO, IS_BINARY, IS_WINDOWS, PREVIOUS_TAG, RUNNING_BETA } from './const'
5
import { dirname, join } from 'path'
6
import { spawn, spawnSync } from 'child_process'
7
-import { DAY, exists, debounceAsync, unzip, prefix, xlate, HOUR, httpWithBody, statWithTimeout } from './misc'
7
+import { DAY, exists, debounceAsync, unzip, prefix, xlate, HOUR, httpStream, statWithTimeout } from './misc'
8
import { createReadStream, existsSync, renameSync, unlinkSync, writeFileSync } from 'fs'
9
import { pluginsWatcher } from './plugins'
10
import { chmod, rename, writeFile, rm } from 'fs/promises'
@@ -134,10 +134,14 @@ export async function update(tagOrUrl: string='') {
134
}
135
if (url) {
136
console.log("downloading", url)
137
- const { body } = await httpWithBody(url)
138
- if (!body)
139
- throw "Download failed for " + url
140
- await writeFile(LOCAL_UPDATE, body)
137
+ try {
138
+ await writeFile(LOCAL_UPDATE, await httpStream(url))
139
+ }
140
+ catch(e: any) {
141
+ await rm(LOCAL_UPDATE).catch(() => {}) // no leftovers
142
+ throw "Download failed for " + url + prefix(' – ', e?.message)
143
+ }
144
+ console.debug("download finished")
145
}
146
const bin = process.execPath
147
const binPath = dirname(bin)