gracefully degrade in case of missing native crc32 module

Massimo Melina committed Jan 1, 2022 at 12:36 UTC d802e7b923c139015259481cd7849c157f91b5db
4 files changed +32 -7
package-lock.json
+18 -2
@@ -1,16 +1,17 @@
1 {
2 "name": "hfs",
3 - "version": "0.3.0",
3 + "version": "0.3.1",
4 "lockfileVersion": 2,
5 "requires": true,
6 "packages": {
7 "": {
8 "name": "hfs",
9 - "version": "0.3.0",
9 + "version": "0.3.1",
10 "license": "GPL-3.0",
11 "dependencies": {
12 "@koa/router": "^10.1.1",
13 "@node-rs/crc32": "^1.3.1",
14 + "buffer-crc32": "https://github.com/rejetto/buffer-crc32.git",
15 "fast-glob": "^3.2.7",
16 "koa": "^2.13.4",
17 "koa-better-http-proxy": "^0.2.9",
@@ -22,6 +23,9 @@
23 "minimist": "^1.2.5",
24 "yaml": "^1.10.2"
25 },
26 + "bin": {
27 + "hfs": "dist/index.js"
28 + },
29 "devDependencies": {
30 "@types/archiver": "^5.1.1",
31 "@types/axios": "^0.14.0",
@@ -892,6 +896,14 @@
896 "ieee754": "^1.1.13"
897 }
898 },
899 + "node_modules/buffer-crc32": {
900 + "version": "0.2.13",
901 + "resolved": "git+ssh://git@github.com/rejetto/buffer-crc32.git#16098518f2d3b75e5c5b2e8b67d11c3a7b35a771",
902 + "license": "MIT",
903 + "engines": {
904 + "node": "*"
905 + }
906 + },
907 "node_modules/bytes": {
908 "version": "3.1.1",
909 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.1.tgz",
@@ -4114,6 +4126,10 @@
4126 "ieee754": "^1.1.13"
4127 }
4128 },
4129 + "buffer-crc32": {
4130 + "version": "git+ssh://git@github.com/rejetto/buffer-crc32.git#16098518f2d3b75e5c5b2e8b67d11c3a7b35a771",
4131 + "from": "buffer-crc32@https://github.com/rejetto/buffer-crc32.git"
4132 + },
4133 "bytes": {
4134 "version": "3.1.1",
4135 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.1.tgz",
package.json
+5 -2
@@ -1,6 +1,6 @@
1 {
2 "name": "hfs",
3 - "version": "0.3.0",
3 + "version": "0.3.1",
4 "description": "HTTP File Server",
5 "keywords": [
6 "file server",
@@ -22,12 +22,15 @@
22 "pkg": {
23 "scripts": "dist/**/*.js",
24 "assets": "dist/frontend/**/*",
25 - "targets": [ "node16-win" ],
25 + "targets": [
26 + "node16-win"
27 + ],
28 "outputPath": "dist"
29 },
30 "dependencies": {
31 "@koa/router": "^10.1.1",
32 "@node-rs/crc32": "^1.3.1",
33 + "buffer-crc32": "https://github.com/rejetto/buffer-crc32.git",
34 "fast-glob": "^3.2.7",
35 "koa": "^2.13.4",
36 "koa-better-http-proxy": "^0.2.9",
src/QuickZipStream.ts
+8 -2
@@ -1,8 +1,14 @@
1 -import { crc32 } from '@node-rs/crc32'
1 import { Readable } from 'stream'
2 +// @ts-ignore
3 +import { crc32number } from 'buffer-crc32'
4
5 const ZIP64_LIMIT = 2**31 -1
6
7 +const crc32provider = import('@node-rs/crc32').then(lib => lib.crc32, () => {
8 + console.debug('using generic lib for crc32')
9 + return crc32number
10 +})
11 +
12 interface ZipSource {
13 path: string
14 data: Readable
@@ -35,7 +41,7 @@ export class QuickZipStream extends Readable {
41 ++this.numberOfFiles
42 let { path, data, size, ts } = value
43 const pathAsBuffer = Buffer.from(path, 'utf8')
38 -
44 + const crc32 = await crc32provider
45 let crc: number | undefined = undefined
46 const offset = this.dataWritten
47 let version = 20
todo.md
+1 -1
@@ -1,5 +1,5 @@
1 # To do
2 -- platform-independent crc32 module
2 +- let user access the folder of a file in a search-result
3 - anti-csrf
4 - file sorting
5 - folders before?