-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added JS generation with emscripten.
Some work left to make sure non-ascii text isn't decompressed to mojibake.
- Loading branch information
1 parent
dfce8d4
commit 52d6257
Showing
4 changed files
with
173 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var Module = { | ||
'preRun': function() { | ||
var _shoco_compress = Module['cwrap']('shoco_compress', 'number', ['string', 'number', 'number', 'number']); | ||
var _shoco_decompress = Module['cwrap']('shoco_decompress', 'number', ['number', 'number', 'number', 'number']); | ||
|
||
window['shoco'] = { | ||
'compress': function(str_in) { | ||
var out_heap = Module['_malloc'](str_in.length * 8); | ||
var out_buffer = new Uint8Array(Module['HEAPU8']['buffer'], out_heap, str_in.length * 8); | ||
var ret = _shoco_compress(str_in, 0, out_buffer.byteOffset, out_buffer.byteLength); | ||
var result = new Uint8Array(out_buffer.subarray(0, ret)); | ||
Module['_free'](out_buffer.byteOffset); | ||
return result; | ||
}, | ||
'decompress': function(cmp) { | ||
var out_heap = Module['_malloc'](cmp.length * 8); | ||
var out_buffer = new Uint8Array(Module['HEAPU8']['buffer'], out_heap, cmp.length * 8); | ||
var in_heap = Module['_malloc'](cmp.byteLength); | ||
var in_buffer = new Uint8Array(Module['HEAPU8']['buffer'], in_heap, cmp.byteLength); | ||
in_buffer.set(new Uint8Array(cmp.buffer)); | ||
var len = _shoco_decompress(in_buffer.byteOffset, cmp.byteLength, out_buffer.byteOffset, out_buffer.byteLength); | ||
result = String.fromCharCode.apply(null, out_buffer.subarray(0, len)); | ||
Module['_free'](in_buffer.byteOffset); | ||
Module['_free'](out_buffer.byteOffset); | ||
return result; | ||
} | ||
} | ||
|
||
if (typeof module !== "undefined") | ||
module.exports = window['shoco']; | ||
} | ||
}; |
Oops, something went wrong.