@samitouri / QOSami-HFS / commits / b3f958e1

fix: quitting on start on old CPUs #633

Massimo Melina committed Oct 15, 2025 at 14:41 UTC b3f958e1fd0a5ef6fed3208e0d42fbd5b07047e6
2 files changed +12 -19
package.json
+5 -7
@@ -27,11 +27,10 @@
27 "dist-uncommitted": "npm run build-all && npm run test-ui && npm run dist-bin",
28 "dist-bin": "npm run dist-modules && npm run dist-bin-win && npm run dist-bin-linux && npm run dist-bin-mac && npm run dist-bin-mac-arm",
29 "dist-modules": "cp package*.json central.json dist && cd dist && npm ci --omit=dev && cd .. && node prune_modules",
30 - "dist-pre": "cd dist && rm -rf node_modules/@node-rs/crc32-*",
31 - "dist-bin-win": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-win32-x64-msvc && pkg . --public -C gzip -t node20-win-x64 && npx resedit-cli --in hfs.exe --icon 1,../hfs.ico --out hfs.exe && zip hfs-windows-x64-$(jq -r .version ../package.json).zip hfs.exe -r plugins && cd ..",
32 - "dist-bin-mac-arm": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-darwin-arm64 && pkg . --public -C gzip -t node20-macos-arm64 && zip hfs-mac-arm64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
33 - "dist-bin-mac": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-darwin-x64 && pkg . --public -C gzip -t node20-macos-x64 && zip hfs-mac-x64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
34 - "dist-bin-linux": "npm run dist-pre && cd dist && npm i -f --no-save --omit=dev @node-rs/crc32-linux-x64-gnu && pkg . --public -C gzip -t node20-linux-x64 && zip hfs-linux-x64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
30 + "dist-bin-win": "cd dist && pkg . --public -C gzip -t node20-win-x64 && npx resedit-cli --in hfs.exe --icon 1,../hfs.ico --out hfs.exe && zip hfs-windows-x64-$(jq -r .version ../package.json).zip hfs.exe -r plugins && cd ..",
31 + "dist-bin-mac-arm": "cd dist && pkg . --public -C gzip -t node20-macos-arm64 && zip hfs-mac-arm64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
32 + "dist-bin-mac": "cd dist && pkg . --public -C gzip -t node20-macos-x64 && zip hfs-mac-x64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
33 + "dist-bin-linux": "cd dist && pkg . --public -C gzip -t node20-linux-x64 && zip hfs-linux-x64-$(jq -r .version ../package.json).zip hfs -r plugins && cd ..",
34 "dist-win": "npm run dist-modules && npm run dist-bin-win",
35 "dist-mac-arm": "npm run dist-modules && npm run dist-bin-mac-arm",
36 "dist-mac": "npm run dist-modules && npm run dist-bin-mac",
@@ -72,10 +71,9 @@
71 },
72 "dependencies": {
73 "@gregoranders/csv": "^0.0.13",
75 - "@node-rs/crc32": "^1.10.6",
74 "@rejetto/kvstorage": "^0.14.1",
75 "acme-client": "^5.4.0",
78 - "buffer-crc32": "^1.0.0",
76 + "crc-32": "^1.2.2",
77 "fast-glob": "^3.3.3",
78 "find-process": "^2.0.0",
79 "formidable": "^3.5.4",
src/QuickZipStream.ts
+7 -12
@@ -1,20 +1,12 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 import { Readable } from 'stream'
4 -import bufferCrc32 from 'buffer-crc32'
5 -const { unsigned } = bufferCrc32
4 import assert from 'assert'
7 -import { try_ } from './misc'
5 +import { buf as crc32 } from 'crc-32'
6
7 const ZIP64_SIZE_LIMIT = 0xffffffff
8 const ZIP64_NUMBER_LIMIT = 0xffff
9
12 -type Crc32Function = (input: string | Buffer, initialState?: number | undefined) => number
13 -const crc32function: Crc32Function = try_(() => require('@node-rs/crc32').crc32 satisfies Crc32Function, () => {
14 - console.warn('using generic lib for crc32')
15 - return unsigned satisfies Crc32Function
16 -})
17 -
10 const FLAGS = 0x0808 // bit3 = no crc in local header + bit11 = utf8
11
12 interface ZipSource {
@@ -152,7 +144,7 @@ export class QuickZipStream extends Readable {
144
145 const cache = sourcePath ? crcCache[sourcePath] : undefined
146 const cacheHit = Number(cache?.ts) === Number(ts)
155 - let crc = cacheHit ? cache!.crc : getData ? crc32function('') : 0
147 + let crc = cacheHit ? cache!.crc : getData ? crc32([]) : 0
148 const extAttr = !mode ? 0 : (mode | 0x8000) * 0x10000 // it's like <<16 but doesn't overflow so easily
149 const entry = { size, crc, pathAsBuffer, ts, offset, version, extAttr }
150 if (!getData) {
@@ -185,7 +177,7 @@ export class QuickZipStream extends Readable {
177 if (!this.controlledPush(chunk)) // destination buffer full
178 data.pause() // slow down
179 if (!cacheHit)
188 - crc = crc32function(chunk, crc)
180 + crc = crc32(chunk, crc)
181 if (this.finished)
182 return data.destroy()
183 })
@@ -295,7 +287,10 @@ function buffer(pairs: number[]) {
287 else if (size === 2)
288 ret.writeUInt16LE(data, offset)
289 else if (size === 4)
298 - ret.writeUInt32LE(data, offset)
290 + if (data < 0) // needed for crc32
291 + ret.writeInt32LE(data, offset)
292 + else
293 + ret.writeUInt32LE(data, offset)
294 else if (size === 8)
295 ret.writeBigUInt64LE(BigInt(data), offset)
296 else