Skip to content

Commit e66a791

Browse files
committed
feat: bzip2-wasm, incremental client packing
1 parent 35f55a4 commit e66a791

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+9450
-2192
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ prisma/*
33
public/*
44
ref/*
55
view/*
6+
src/3rdparty/*

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ prisma/*
33
public/*
44
ref/*
55
view/*
6+
src/3rdparty/*
67

78
*.json
89
*.yml

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"type": "module",
55
"imports": {
6+
"#3rdparty/*": "./src/3rdparty/*",
67
"#jagex2/*": "./src/jagex2/*",
78
"#lostcity/*": "./src/lostcity/*"
89
},
@@ -15,21 +16,22 @@
1516
"maintenance": "npm run ts-loader src/lostcity/maintenance.ts",
1617
"web": "npm run ts-loader src/lostcity/web.ts",
1718
"dev": "concurrently \"nodemon src/lostcity/app.ts\" \"npm run server:watch\"",
18-
"client:pack": "npm run ts-loader src/lostcity/tools/client/all/pack.ts",
19+
"client:pack": "npm run ts-loader src/lostcity/tools/pack/client.ts",
1920
"client:clean": "npm run ts-loader src/lostcity/tools/client/clean.ts",
20-
"script:symbols": "npm run ts-loader src/lostcity/tools/server/scripts/symbols.ts",
2121
"script:compile": "java -jar RuneScriptCompiler.jar",
2222
"script:run": "npm run ts-loader src/lostcity/tools/server/runscript.ts",
23-
"server:pack": "npm run ts-loader src/lostcity/tools/server/all/pack.ts",
23+
"server:pack": "npm run ts-loader src/lostcity/tools/pack/server.ts",
2424
"server:clean": "npm run ts-loader src/lostcity/tools/server/clean.ts",
25-
"server:build": "npm run server:pack && npm run script:symbols && npm run script:compile",
25+
"server:build": "npm run server:pack && npm run script:compile",
2626
"server:watch": "watch \"npm run server:build\" ./data/src/scripts ./src/lostcity/tools",
2727
"test": "jest",
2828
"lint": "eslint . --ext .ts --ext .js",
2929
"drops": "npm run ts-loader src/lostcity/tools/server/drops.ts",
3030
"db:migrate": "prisma migrate deploy",
3131
"db:reset": "prisma migrate reset --force",
32-
"db:schema": "prisma migrate dev"
32+
"db:schema": "prisma migrate dev",
33+
"clean": "npm run client:clean && npm run server:clean",
34+
"build": "npm run client:pack && npm run server:build"
3335
},
3436
"prisma": {
3537
"seed": "npm run ts-loader src/lostcity/db/seed.ts"

src/3rdparty/bzip2-wasm/LICENSE

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
--------------------------------------------------------------------------
3+
4+
This program, "bzip2", the associated library "libbzip2", and all
5+
documentation, are copyright (C) 1996-2019 Julian R Seward. All
6+
rights reserved.
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions
10+
are met:
11+
12+
1. Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
15+
2. The origin of this software must not be misrepresented; you must
16+
not claim that you wrote the original software. If you use this
17+
software in a product, an acknowledgment in the product
18+
documentation would be appreciated but is not required.
19+
20+
3. Altered source versions must be plainly marked as such, and must
21+
not be misrepresented as being the original software.
22+
23+
4. The name of the author may not be used to endorse or promote
24+
products derived from this software without specific prior written
25+
permission.
26+
27+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
28+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
31+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
35+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38+
39+
Julian Seward, [email protected]
40+
bzip2/libbzip2 version 1.0.8 of 13 July 2019
41+
42+
--------------------------------------------------------------------------

src/3rdparty/bzip2-wasm/README.md

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# bzip2-wasm
2+
3+
(de)compress buffers in node and browser using wasm-compiled
4+
[bzip2](https://sourceware.org/bzip2/).
5+
6+
## install
7+
8+
$ npm install bzip2-wasm
9+
10+
## example
11+
```javascript
12+
import BZip2 from "wasm-bzip2";
13+
import fs from 'fs';
14+
15+
const bzip2 = new BZip2();
16+
17+
await bzip2.init();
18+
19+
const licenseText = fs.readFileSync('./LICENSE');
20+
console.log('original length:', licenseText.length);
21+
22+
const compressed = bzip2.compress(licenseText);
23+
console.log('compressed length:', compressed.length);
24+
25+
const decompressed = bzip2.decompress(compressed, licenseText.length);
26+
console.log('decompressed length:', decompressed.length);
27+
```
28+
29+
## api
30+
31+
### bzip2 = new BZip2()
32+
33+
### async bzip2.init()
34+
fetch and load the wasm. required for following methods.
35+
36+
### bzip2.compress(decompressed, blockSize = 5, compressedSize = decompressed.length)
37+
compress an array of bytes.
38+
39+
`decompressed` should be array-like
40+
([TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
41+
or regular) of bytes.
42+
43+
`blockSize` should be a Number between 1-9 to determine block size (multiplied
44+
by 100k). default is 5 (500k).
45+
46+
`compressedLength` should be a Number that is at least large or larger
47+
than the resulting compressed data. default is `decompressed.length`.
48+
49+
returns a
50+
[`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
51+
of compressed data.
52+
53+
### bzip2.decompress(compressed = [], decompressedLength = 0)
54+
decompress a compressed array of bytes.
55+
56+
`compressed` should be array-like
57+
([TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
58+
or regular) of bytes.
59+
60+
`decompressedLength` should be a Number that is at least large or larger
61+
than the resulting decompressed data.
62+
63+
returns a
64+
[`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
65+
of decompressed data.
66+
67+
## license
68+
This program, "bzip2", the associated library "libbzip2", and all
69+
documentation, are copyright (C) 1996-2019 Julian R Seward. All
70+
rights reserved.
71+
72+
Redistribution and use in source and binary forms, with or without
73+
modification, are permitted provided that the following conditions
74+
are met:
75+
76+
1. Redistributions of source code must retain the above copyright
77+
notice, this list of conditions and the following disclaimer.
78+
79+
2. The origin of this software must not be misrepresented; you must
80+
not claim that you wrote the original software. If you use this
81+
software in a product, an acknowledgment in the product
82+
documentation would be appreciated but is not required.
83+
84+
3. Altered source versions must be plainly marked as such, and must
85+
not be misrepresented as being the original software.
86+
87+
4. The name of the author may not be used to endorse or promote
88+
products derived from this software without specific prior written
89+
permission.
90+
91+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
92+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
93+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
94+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
95+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
97+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
98+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
99+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
100+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
101+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102+
103+
Julian Seward, [email protected]
104+
bzip2/libbzip2 version 1.0.8 of 13 July 2019
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CC = emcc
2+
SRC = $(wildcard *.c )
3+
CFLAGS = -Wall -Winline -O2 -D_FILE_OFFSET_BITS=64
4+
LDFLAGS = -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME=loadBZip2WASM
5+
LDFLAGS += -s EXPORTED_FUNCTIONS="[_BZ2_bzBuffToBuffDecompress,_BZ2_bzBuffToBuffCompress,_malloc,_free]"
6+
LDFLAGS += -s EXPORTED_RUNTIME_METHODS="[setValue,getValue]"
7+
LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
8+
OBJ = $(SRC:.c=.o)
9+
10+
bzip2.mjs: $(OBJ)
11+
$(CC) -o $@ $^ $(LDFLAGS)
12+
patch bzip2.mjs < node.diff
13+
14+
clean:
15+
rm -f *.wasm *.o bzip2.mjs

0 commit comments

Comments
 (0)