Skip to content

Commit 18dd2cc

Browse files
authored
Merge pull request #124 from GordonSmith/BASE91
feat: Add Base91 wasm
2 parents 0667815 + 7063b76 commit 18dd2cc

31 files changed

+877
-240
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939

4040
# Initializes the CodeQL tools for scanning.
4141
- name: Initialize CodeQL
42-
uses: github/codeql-action/init@v1
42+
uses: github/codeql-action/init@v2
4343
with:
4444
languages: ${{ matrix.language }}
4545
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -50,7 +50,7 @@ jobs:
5050
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5151
# If this step fails, then you should remove it and run the build manually (see below)
5252
- name: Autobuild
53-
uses: github/codeql-action/autobuild@v1
53+
uses: github/codeql-action/autobuild@v2
5454

5555
# ℹ️ Command-line programs to run using the OS shell.
5656
# 📚 https://git.io/JvXDl
@@ -64,4 +64,4 @@ jobs:
6464
# make release
6565

6666
- name: Perform CodeQL Analysis
67-
uses: github/codeql-action/analyze@v1
67+
uses: github/codeql-action/analyze@v2

.github/workflows/ossar-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ jobs:
4444

4545
# Upload results to the Security tab
4646
- name: Upload OSSAR results
47-
uses: github/codeql-action/upload-sarif@v1
47+
uses: github/codeql-action/upload-sarif@v2
4848
with:
4949
sarif_file: ${{ steps.ossar.outputs.sarifFile }}

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
/.nyc_output
2-
.vscode/ipch
2+
/.vscode/c_cpp_properties.json
3+
/.vscode/ipch
4+
/.vscode/settings.json
5+
/bin
36
/build
47
/coverage
58
/dist
69
/dist-test
710
/emsdk*
8-
/src-expat
9-
/src-graphviz
1011
/lib-*
1112
/node_modules
13+
/rust
14+
/src-*
1215
/tmp
1316
/types
1417
/vcpkg
1518
*.tsbuildinfo
16-
/.vscode/c_cpp_properties.json
17-
/.vscode/settings.json

.vscode/launch.json

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
"url": "http://localhost:8000/hw-zstd.html",
2727
"webRoot": "${workspaceRoot}"
2828
},
29+
{
30+
"name": "hw-base91.html",
31+
"type": "msedge",
32+
"request": "launch",
33+
"url": "http://localhost:8000/hw-base91.html",
34+
"webRoot": "${workspaceRoot}"
35+
},
2936
{
3037
"name": "test-browser",
3138
"type": "msedge",
@@ -50,9 +57,31 @@
5057
],
5158
"type": "node"
5259
},
60+
{
61+
"name": "sfx-wasm",
62+
"program": "${workspaceFolder}/bin/sfx-wasm.mjs",
63+
"request": "launch",
64+
"args": [
65+
"./build/cpp/base91/base91lib.wasm"
66+
],
67+
"skipFiles": [
68+
"<node_internals>/**"
69+
],
70+
"type": "node"
71+
},
72+
{
73+
"name": "cli rollup wasm",
74+
"program": "${workspaceFolder}/output-node/test-wasm.js",
75+
"request": "launch",
76+
"args": [],
77+
"skipFiles": [
78+
"<node_internals>/**"
79+
],
80+
"type": "node"
81+
},
5382
{
5483
"name": "CLI",
55-
"program": "${workspaceFolder}/bin/cli.js",
84+
"program": "${workspaceFolder}/bin/dot-wasm.mjs",
5685
"request": "launch",
5786
"args": [
5887
"-K neato",
@@ -66,7 +95,7 @@
6695
},
6796
{
6897
"name": "CLI Version",
69-
"program": "${workspaceFolder}/bin/cli.js",
98+
"program": "${workspaceFolder}/bin/dot-wasm.mjs",
7099
"request": "launch",
71100
"args": [
72101
"-v"

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ SET(EM_FLAGS
1111
"-s INVOKE_RUN=0"
1212
"-s ALLOW_MEMORY_GROWTH=1"
1313
"-s WASM=1"
14-
"-s MODULARIZE"
1514
"-s ENVIRONMENT=web"
1615
"-s FILESYSTEM=0"
1716
# "-s MINIMAL_RUNTIME=1"
@@ -21,7 +20,7 @@ SET(EM_FLAGS
2120
"-s USE_ES6_IMPORT_META=0"
2221
# "-s WASM_BIGINT=1"
2322
"--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/pre.js"
24-
# "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/post.js"
23+
"--post-js ${CMAKE_CURRENT_SOURCE_DIR}/cpp/src/post.js"
2524
)
2625

2726
IF (CMAKE_BUILD_TYPE STREQUAL "Debug")

README.md

Lines changed: 146 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Built with:
2929
- [Zstandard (zstd)](#zstandard)
3030
- [Hello World](#zstandard-hello-world)
3131
- [API](#zstandard-api)
32+
- [Base91](#base91)
33+
- [Hello World](#base91-hello-world)
34+
- [API](#base91-api)
3235
- [Utilities](#utility)
3336
- [Building @hpcc-js/wasm](#building-hpcc-js-wasm)
3437

@@ -108,7 +111,7 @@ GraphViz WASM library, see [graphviz.org](https://www.graphviz.org/) for c++ det
108111

109112
To call `dot-wasm` without installing:
110113
```
111-
npx @hpcc-js/wasm [options] fileOrDot
114+
npx -p @hpcc-js/wasm dot-wasm [options] fileOrDot
112115
```
113116

114117
To install the global command `dot-wasm` via NPM:
@@ -121,38 +124,35 @@ Usage:
121124
Usage: dot-wasm [options] fileOrDot
122125
123126
Options:
124-
--version Show version number [boolean]
125-
-K, --layout Set layout engine (circo | dot | fdp | sfdp | neato | osage
126-
| patchwork | twopi). By default, dot is used.
127-
-T, --format Set output language to one of the supported formats (svg,
128-
dot, json, dot_json, xdot_json, plain, plain-ext). By
129-
default, svg is produced.
127+
--version Show version number [boolean]
128+
-K, --layout Set layout engine (circo | dot | fdp | sfdp | neato | osage | patchwo
129+
rk | twopi). By default, dot is used.
130+
-T, --format Set output language to one of the supported formats (svg | dot | json
131+
| dot_json | xdot_json | plain | plain-ext). By default, svg is prod
132+
uced.
130133
-n, --neato-no-op Sets no-op flag in neato.
131-
"-n 1" assumes neato nodes have already been positioned and
132-
all nodes have a pos attribute giving the positions. It
133-
then performs an optional adjustment to remove node-node
134-
overlap, depending on the value of the overlap attribute,
135-
computes the edge layouts, depending on the value of the
136-
splines attribute, and emits the graph in the appropriate
137-
format.
138-
"-n 2" Use node positions as specified, with no adjustment
139-
to remove node-node overlaps, and use any edge layouts
140-
already specified by the pos attribute. neato computes an
141-
edge layout for any edge that does not have a pos
142-
attribute. As usual, edge layout is guided by the splines
143-
attribute.
144-
-y, --invert-y By default, the coordinate system used in generic output
145-
formats, such as attributed dot, extended dot, plain and
146-
plain-ext, is the standard cartesian system with the origin
147-
in the lower left corner, and with increasing y coordinates
148-
as points move from bottom to top. If the -y flag is used,
149-
the coordinate system is inverted, so that increasing
150-
values of y correspond to movement from top to bottom.
151-
-h, --help Show help [boolean]
134+
"-n 1" assumes neato nodes have already bee
135+
n positioned and all nodes have a pos attribute giving the positions.
136+
It then performs an optional adjustment to remove node-node overlap,
137+
depending on the value of the overlap attribute, computes the edge l
138+
ayouts, depending on the value of the splines attribute, and emits th
139+
e graph in the appropriate format.
140+
"-n 2" Use node positions as speci
141+
fied, with no adjustment to remove node-node overlaps, and use any ed
142+
ge layouts already specified by the pos attribute. neato computes an
143+
edge layout for any edge that does not have a pos attribute. As usual
144+
, edge layout is guided by the splines attribute.
145+
-y, --invert-y By default, the coordinate system used in generic output formats, suc
146+
h as attributed dot, extended dot, plain and plain-ext, is the standa
147+
rd cartesian system with the origin in the lower left corner, and wit
148+
h increasing y coordinates as points move from bottom to top. If the
149+
-y flag is used, the coordinate system is inverted, so that increasin
150+
g values of y correspond to movement from top to bottom.
151+
-v Echo GraphViz library version
152+
-h, --help Show help [boolean]
152153
153154
Examples:
154-
dot-wasm -K neato -T xdot ./input.dot Execute NEATO layout and outputs XDOT
155-
format.
155+
dot-wasm -K neato -T xdot ./input.dot Execute NEATO layout and outputs XDOT format.
156156
```
157157

158158
### GraphViz Hello World
@@ -515,6 +515,122 @@ A note on compressionLevel: The library supports regular compression levels fro
515515

516516
---
517517

518+
## Base91
519+
_Similar to Base 64, but uses more characters resulting in smaller strings._
520+
521+
Base 91 WASM library, similar to Base 64 but uses more characters resulting in smaller strings, see [Base91](https://base91.sourceforge.net/) for more details.
522+
523+
### Base91 Hello World
524+
525+
```html
526+
<!DOCTYPE html>
527+
<html>
528+
529+
<head>
530+
<meta charset="UTF-8">
531+
<title>Base91 WASM</title>
532+
</head>
533+
534+
<body>
535+
<div id="placeholder"></div>
536+
<script type="module">
537+
import { Base91 } from "./dist/index.es6.js";
538+
//import { Base91 } from "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/index.es6.js";
539+
540+
const base91 = await Base91.load();
541+
const data = new Uint8Array(Array.from({ length: 100 }, (_, i) => Math.random() * 100));
542+
const encoded_data = await base91.encode(data);
543+
const decoded_data = await base91.decode(encoded_data);
544+
document.getElementById("placeholder").innerHTML = `\
545+
<ul>
546+
<li>Data Size (bytes): ${data.byteLength}</li>
547+
<li>Endoded Size (bytes): ${encoded_data.length}</li>
548+
<li>Decoded Size (bytes): ${decoded_data.byteLength}</li>
549+
</ul>
550+
<h4>Data: </h4>
551+
<code>
552+
${data}
553+
</code>
554+
<h4>Base 91: </h4>
555+
<code id="base91">
556+
</code>
557+
<h4>Decoded: </h4>
558+
<code>
559+
${decoded_data}
560+
</code>
561+
`;
562+
document.getElementById("base91").innerText = encoded_data;
563+
</script>
564+
565+
</body>
566+
567+
</html>
568+
```
569+
570+
### Base91 API
571+
572+
#### Interfaces
573+
574+
<a name="Options" href="#Base91Options">#</a> **Options** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")
575+
576+
Options structure for advanced loading.
577+
578+
```typescript
579+
interface Options {
580+
wasmFolder?: string;
581+
wasmBinary?: ArrayBuffer;
582+
}
583+
```
584+
585+
* _wasmFolder_: An optional `string` specifying the location of wasm file.
586+
* _wasmBinary_: An optional "pre-fetched" copy of the wasm binary as returned from `XHR` or `fetch`.
587+
588+
<a name="Base91" href="#Base91">#</a> **Base91** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")
589+
590+
Conceptual interface for TypeScript/JavaScript wrapper API
591+
592+
```typescript
593+
interface Base91 {
594+
static load(options?: Options): Promise<Base91>;
595+
version(): string;
596+
597+
encode(data: Uint8Array): string;
598+
decode(array: string): Uint8Array;
599+
}
600+
```
601+
602+
<a name="base91Load" href="#base91Load">#</a> **Base91.load**(_options_?: **Options**): **Promise\<Base91\>** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")
603+
604+
Loads and initializes the Base91 wasm library, returns a Promise to `Base91`:
605+
```typescript
606+
const base91 = await Base91.load();
607+
...dostuff...
608+
```
609+
or
610+
```typescript
611+
Base91.load().then(base91 => {...dostuff...});
612+
```
613+
614+
<a name="base91Version" href="#base91Version">#</a> **base91.version**(): **string** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")
615+
616+
* **_returns_**: The Base91 library Version.
617+
618+
<a name="base91Encode" href="#base91Encode">#</a> **base91.encode**(_data_: **Uint8Array**): **string** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")
619+
620+
* **_data_**: Raw data to encode.
621+
* **_returns_**: Encoded string.
622+
623+
Encodes the raw data.
624+
625+
<a name="base91Decode" href="#base91Decode">#</a> **base91.decode**(_str_: **string**): **Uint8Array** · [<>](https://github.com/hpcc-systems/hpcc-js-wasm/blob/trunk/src/base91.ts "Source")
626+
627+
* **_str_**: String to decode.
628+
* **_returns_**: Decoded data.
629+
630+
Decodes the raw data.
631+
632+
---
633+
518634
## Utility
519635

520636
Utility functions unrelated to any specific wasm APIs

cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
ADD_SUBDIRECTORY(base91)
12
ADD_SUBDIRECTORY(expat)
23
ADD_SUBDIRECTORY(graphviz)
34
ADD_SUBDIRECTORY(zstd)

cpp/base91/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
PROJECT(base91lib)
2+
3+
find_package(unofficial-base91 CONFIG REQUIRED)
4+
5+
# See: https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
6+
SET(EM_FLAGS
7+
${EM_FLAGS}
8+
"-s EXPORT_NAME='${CMAKE_PROJECT_NAME}'"
9+
"-s EXPORTED_FUNCTIONS=\"[]\""
10+
"-s EXPORTED_RUNTIME_METHODS=\"[]\""
11+
"--post-js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js"
12+
)
13+
STRING(REPLACE ";" " " LINK_FLAGS "${EM_FLAGS}")
14+
15+
# Generate Glue from IDL file ---
16+
ADD_CUSTOM_COMMAND(
17+
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/main.idl
18+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/main_glue.js ${CMAKE_CURRENT_BINARY_DIR}/main_glue.cpp
19+
COMMAND python3 ${CMAKE_BINARY_DIR}/../emsdk/upstream/emscripten/tools/webidl_binder.py ${CMAKE_CURRENT_SOURCE_DIR}/main.idl ${CMAKE_CURRENT_BINARY_DIR}/main_glue
20+
)
21+
SET_PROPERTY(SOURCE main.cpp APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/main_glue.cpp)
22+
# --- --- ---
23+
24+
INCLUDE_DIRECTORIES(
25+
${VCPKG_INCLUDE_DIR}
26+
${CMAKE_CURRENT_BINARY_DIR}
27+
)
28+
29+
ADD_EXECUTABLE(base91lib
30+
main.cpp
31+
)
32+
33+
SET_TARGET_PROPERTIES(base91lib PROPERTIES LINK_FLAGS "${LINK_FLAGS} -s ENVIRONMENT=webview")
34+
35+
TARGET_LINK_LIBRARIES(base91lib
36+
PRIVATE unofficial::base91::base91
37+
)
38+
39+
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/base91lib.wasm DESTINATION dist COMPONENT runtime)
40+
41+
IF (CMAKE_BUILD_TYPE STREQUAL "Debug")
42+
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/base91lib.wasm.map DESTINATION dist COMPONENT runtime)
43+
ENDIF ()

0 commit comments

Comments
 (0)