Skip to content

Commit b22b469

Browse files
committed
fix(postinstall): bump to 1.1.11, fix download backpressure
1 parent a7f58db commit b22b469

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "1.1.10",
6+
"version": "1.1.11",
77
"description": "",
88
"main": "dist/index.js",
99
"bin": {

scripts/postinstall.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,19 @@ async function download(url, outPath) {
8888
`Download failed: HTTP ${res.status} ${res.statusText}\nURL: ${url}`,
8989
);
9090
}
91+
// Use arrayBuffer for reliability; postinstall runs once so 98MB in memory is fine
9192
const total = parseInt(res.headers.get("content-length") || "0", 10);
92-
let downloaded = 0;
93-
const reader = res.body.getReader();
94-
const ws = createWriteStream(outPath);
95-
const logInterval = setInterval(() => {
96-
if (total > 0) {
97-
process.stderr.write(
98-
`\r Downloading nuwax-codex ${CODEX_VERSION}${((downloaded / total) * 100).toFixed(0)}%`,
99-
);
100-
}
101-
}, 500);
102-
try {
103-
while (true) {
104-
const { done, value } = await reader.read();
105-
if (done) break;
106-
ws.write(value);
107-
downloaded += value.length;
108-
}
109-
} finally {
110-
clearInterval(logInterval);
111-
ws.end();
93+
const arrayBuffer = await res.arrayBuffer();
94+
const buffer = Buffer.from(arrayBuffer);
95+
if (total > 0 && buffer.length !== total) {
96+
throw new Error(
97+
`Download incomplete: got ${buffer.length} bytes, expected ${total}`,
98+
);
11299
}
113-
process.stderr.write("\n");
100+
createWriteStream(outPath).end(buffer);
101+
process.stderr.write(
102+
` Downloaded ${(buffer.length / 1024 / 1024).toFixed(0)} MB\n`,
103+
);
114104
}
115105

116106
async function main() {

0 commit comments

Comments
 (0)