Skip to content

Commit

Permalink
build artif
Browse files Browse the repository at this point in the history
  • Loading branch information
SnosMe committed Nov 14, 2023
1 parent 1dde1e0 commit d1d83c1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 58 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: mymindstorm/setup-emsdk@v10
- uses: actions/checkout@v4
- uses: mymindstorm/setup-emsdk@v12
- run: emcmake cmake -B build -DCMAKE_BUILD_TYPE=Release
- run: cmake --build build
- run: npm pack
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: package
path: ooz-wasm-*.tgz
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target_link_options(ooz PRIVATE
"SHELL:-s WASM=1"
"SHELL:-s FILESYSTEM=0"
"SHELL:-s MODULARIZE=1"
"SHELL:-s EXPORT_ES6=1"
"SHELL:-s STRICT=1"
"SHELL:-s SINGLE_FILE=1"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
Expand Down
92 changes: 38 additions & 54 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,56 @@
'use strict'
import oozFactory from './build/ooz.js';

var oozModule = require('./build/ooz.js');
const OOZ_SAFE_SPACE = 64;

var OOZ_SAFE_SPACE = 64;

var module_ = null;
var lastDecompressionPtr_ = 0;

function load () {
if (!module_) {
module_ = oozModule();
}
return module_;
}
const oozInst = await oozFactory();
let lastDecompressionPtr_ = 0;

/**
* @param {Uint8Array} data
* @param {number} rawSize
* @returns {Promise<Uint8Array>}
* @param {Uint8Array} data
* @param {number} rawSize
* @returns {Uint8Array}
*/
function decompressUnsafe (data, rawSize) {
return load().then(module => {
if (lastDecompressionPtr_) {
module._free(lastDecompressionPtr_);
lastDecompressionPtr_ = 0;
}
export function decompressUnsafe (data, rawSize) {
if (lastDecompressionPtr_) {
oozInst._free(lastDecompressionPtr_);
lastDecompressionPtr_ = 0;
}

var compressedPtr = module._malloc(data.byteLength);
module.HEAPU8.set(data, compressedPtr);
const compressedPtr = oozInst._malloc(data.byteLength);
oozInst.HEAPU8.set(data, compressedPtr);

var decompressedPtr = module._malloc(rawSize + OOZ_SAFE_SPACE);
lastDecompressionPtr_ = decompressedPtr;
const decompressedPtr = oozInst._malloc(rawSize + OOZ_SAFE_SPACE);
lastDecompressionPtr_ = decompressedPtr;

var res = module._Kraken_Decompress(
compressedPtr, data.byteLength,
decompressedPtr, rawSize
);
const res = oozInst._Kraken_Decompress(
compressedPtr, data.byteLength,
decompressedPtr, rawSize
);

module._free(compressedPtr);
oozInst._free(compressedPtr);

if (res < 0) {
throw new Error('Failed to decode');
}
if (res !== rawSize) {
throw new Error('Decompresed size is different from expected');
}
if (res < 0) {
throw new Error('Failed to decode');
}
if (res !== rawSize) {
throw new Error('Decompresed size is different from expected');
}

return module.HEAPU8.subarray(decompressedPtr, decompressedPtr + rawSize);
})
return oozInst.HEAPU8.subarray(decompressedPtr, decompressedPtr + rawSize);
}

/**
* @param {Uint8Array} data
* @param {number} rawSize
* @returns {Promise<Uint8Array>}
* @param {Uint8Array} data
* @param {number} rawSize
* @returns {Uint8Array}
*/
function decompress (data, rawSize) {
return decompressUnsafe(data, rawSize).then(decompressed => {
const decompressedCopy = new Uint8Array(decompressed.byteLength);
decompressedCopy.set(decompressed);
export function decompress (data, rawSize) {
const decompressed = decompressUnsafe(data, rawSize);
const decompressedCopy = new Uint8Array(decompressed.byteLength);
decompressedCopy.set(decompressed);

module._free(lastDecompressionPtr_);
lastDecompressionPtr_ = 0;
oozInst._free(lastDecompressionPtr_);
lastDecompressionPtr_ = 0;

return decompressedCopy;
});
return decompressedCopy;
}

exports.load = load;
exports.decompressUnsafe = decompressUnsafe;
exports.decompress = decompress;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "ooz-wasm",
"version": "1.0.1",
"version": "2.0.0",
"type": "module",
"author": {
"name": "Alexander Drozdov"
},
Expand Down

0 comments on commit d1d83c1

Please sign in to comment.