diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index c594bbd..0d3c8f3 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -4,5 +4,5 @@ contact_links: url: https://github.com/facebook/zstd about: Check the official zstd documentation before opening new issues. - name: Plugin Documentation - url: https://github.com/landamessenger/zstandard/wiki + url: https://github.com/vypdev/zstandard/wiki about: Check the plugin/cli documentation before opening new issues. \ No newline at end of file diff --git a/.github/workflows/push_checks_android.yml b/.github/workflows/push_checks_android.yml index 057e556..10bb639 100644 --- a/.github/workflows/push_checks_android.yml +++ b/.github/workflows/push_checks_android.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' # paths: # - "zstandard_android/**" diff --git a/.github/workflows/push_checks_cli.yml b/.github/workflows/push_checks_cli.yml index a3cef49..adeedd0 100644 --- a/.github/workflows/push_checks_cli.yml +++ b/.github/workflows/push_checks_cli.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' #paths: # - "zstandard_cli/**" diff --git a/.github/workflows/push_checks_ios.yml b/.github/workflows/push_checks_ios.yml index bc9f9fd..977ec9c 100644 --- a/.github/workflows/push_checks_ios.yml +++ b/.github/workflows/push_checks_ios.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' #paths: # - "zstandard_ios/**" diff --git a/.github/workflows/push_checks_linux.yml b/.github/workflows/push_checks_linux.yml index fa1577f..f008441 100644 --- a/.github/workflows/push_checks_linux.yml +++ b/.github/workflows/push_checks_linux.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' #paths: # - "zstandard_linux/**" diff --git a/.github/workflows/push_checks_macos.yml b/.github/workflows/push_checks_macos.yml index 3cadd9a..999ebfd 100644 --- a/.github/workflows/push_checks_macos.yml +++ b/.github/workflows/push_checks_macos.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' #paths: # - "zstandard_macos/**" diff --git a/.github/workflows/push_checks_platform_interface.yml b/.github/workflows/push_checks_platform_interface.yml index 6d9065f..6383063 100644 --- a/.github/workflows/push_checks_platform_interface.yml +++ b/.github/workflows/push_checks_platform_interface.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' #paths: # - "zstandard_platform_interface/**" diff --git a/.github/workflows/push_checks_web.yml b/.github/workflows/push_checks_web.yml index 5a4a4bf..2e09b73 100644 --- a/.github/workflows/push_checks_web.yml +++ b/.github/workflows/push_checks_web.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' #paths: # - "zstandard_web/**" diff --git a/.github/workflows/push_checks_windows.yml b/.github/workflows/push_checks_windows.yml index 4a3d746..c3e8ce1 100644 --- a/.github/workflows/push_checks_windows.yml +++ b/.github/workflows/push_checks_windows.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' #paths: # - "zstandard_windows/**" diff --git a/.github/workflows/push_checks_zstandard.yml b/.github/workflows/push_checks_zstandard.yml index 404b850..84a4bb1 100644 --- a/.github/workflows/push_checks_zstandard.yml +++ b/.github/workflows/push_checks_zstandard.yml @@ -7,7 +7,7 @@ on: - '!develop' - '!release/**' - '!hotfix/**' - # - '!master' + - '!master' #paths: # - "zstandard/**" diff --git a/CHANGELOG.md b/CHANGELOG.md index a60496b..224bf31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/README.md b/README.md index 10808ea..1d2dd49 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![pub package](https://img.shields.io/pub/v/zstandard.svg)](https://pub.dev/packages/zstandard) [![pub package](https://img.shields.io/pub/v/zstandard_cli.svg)](https://pub.dev/packages/zstandard_cli) -[![codecov](https://codecov.io/gh/landamessenger/zstandard/graph/badge.svg)](https://codecov.io/gh/landamessenger/zstandard) +[![codecov](https://codecov.io/gh/vypdev/zstandard/graph/badge.svg)](https://codecov.io/gh/vypdev/zstandard) # Zstandard @@ -123,27 +123,27 @@ void main() async { #### macOS -

-

+

+

#### Windows -

-

+

+

#### Linux -

-

+

+

#### Flutter Plugin (Android, iOS, macOS, Web, Windows, Linux) -

-

-

-

-

-

+

+

+

+

+

+

--- diff --git a/docs/architecture/web-implementation.md b/docs/architecture/web-implementation.md index 73fdaa4..0be9851 100644 --- a/docs/architecture/web-implementation.md +++ b/docs/architecture/web-implementation.md @@ -61,7 +61,7 @@ zstd is built with Emscripten. High-level steps: 3. Run `emcc` on the zstd sources with flags for WASM, exported functions (`ZSTD_compress`, `ZSTD_decompress`, `ZSTD_compressBound`, `ZSTD_getFrameContentSize`, `malloc`, `free`), and output name. 4. Add the wrapper functions `compressData` and `decompressData` in `zstd.js` (or a separate script) that allocate buffers, call the exported C functions, and return the result or null. -Detailed commands and wrapper code are in the [zstandard_web README](https://github.com/landamessenger/zstandard/tree/master/zstandard_web) and in [Platforms — Web](../platforms/web.md). +Detailed commands and wrapper code are in the [zstandard_web README](https://github.com/vypdev/zstandard/tree/master/zstandard_web) and in [Platforms — Web](../platforms/web.md). ## Small Data Handling diff --git a/docs/development/CONTRIBUTING.md b/docs/development/CONTRIBUTING.md index 61b52c7..f4811a4 100644 --- a/docs/development/CONTRIBUTING.md +++ b/docs/development/CONTRIBUTING.md @@ -48,7 +48,7 @@ When changing the platform interface, ensure all platform implementations are up ## Questions -- Open a [GitHub Issue](https://github.com/landamessenger/zstandard/issues) for bugs or feature requests. -- Use [GitHub Discussions](https://github.com/landamessenger/zstandard/discussions) for questions and ideas. +- Open a [GitHub Issue](https://github.com/vypdev/zstandard/issues) for bugs or feature requests. +- Use [GitHub Discussions](https://github.com/vypdev/zstandard/discussions) for questions and ideas. Thank you for contributing. diff --git a/docs/development/ci-cd.md b/docs/development/ci-cd.md index f04c65e..985ebe4 100644 --- a/docs/development/ci-cd.md +++ b/docs/development/ci-cd.md @@ -10,7 +10,7 @@ The repository uses **GitHub Actions** for: - **Release workflow**: Version bumping, building precompiled CLI libraries, tagging, and publishing to pub.dev. - **Hotfix workflow**: Expedited fixes and releases when needed. -Workflows are in [`.github/workflows/`](https://github.com/landamessenger/zstandard/tree/master/.github/workflows). +Workflows are in [`.github/workflows/`](https://github.com/vypdev/zstandard/tree/master/.github/workflows). ## Push check workflows @@ -40,7 +40,7 @@ Each package has a dedicated workflow that runs on push to non-protected branche ## Release workflow -**File**: [`.github/workflows/release_workflow.yml`](https://github.com/landamessenger/zstandard/blob/master/.github/workflows/release_workflow.yml) +**File**: [`.github/workflows/release_workflow.yml`](https://github.com/vypdev/zstandard/blob/master/.github/workflows/release_workflow.yml) Triggered manually (**workflow_dispatch**) with inputs such as version, title, changelog, and optional issue reference. @@ -58,7 +58,7 @@ The workflow uses **self-hosted** runners for macOS, Linux, and Windows to build ## Hotfix workflow -**File**: [`.github/workflows/hotfix_workflow.yml`](https://github.com/landamessenger/zstandard/blob/master/.github/workflows/hotfix_workflow.yml) +**File**: [`.github/workflows/hotfix_workflow.yml`](https://github.com/vypdev/zstandard/blob/master/.github/workflows/hotfix_workflow.yml) Used for expedited fixes (e.g. security or critical bugs). Typically triggered manually and may skip some steps or use a shorter path to release. See the workflow file and team docs for details. @@ -73,7 +73,7 @@ To mimic CI locally: ## Build automation scripts -Scripts under [**scripts/**](https://github.com/landamessenger/zstandard/tree/master/scripts) help build native libraries and run tests locally: +Scripts under [**scripts/**](https://github.com/vypdev/zstandard/tree/master/scripts) help build native libraries and run tests locally: - `build_macos.sh`, `build_linux.sh`, `build_windows.bat`: Build precompiled zstd libraries for the CLI. - `build_android.sh`, `build_ios.sh`: Build or prepare the Android/iOS plugin. diff --git a/docs/development/setup.md b/docs/development/setup.md index 9860c12..6c55b40 100644 --- a/docs/development/setup.md +++ b/docs/development/setup.md @@ -19,14 +19,14 @@ Optional, for native work: ## Clone the Repository ```bash -git clone https://github.com/landamessenger/zstandard.git +git clone https://github.com/vypdev/zstandard.git cd zstandard ``` If you use a fork: ```bash -git remote add upstream https://github.com/landamessenger/zstandard.git +git remote add upstream https://github.com/vypdev/zstandard.git ``` ## Get Dependencies diff --git a/docs/guides/installation.md b/docs/guides/installation.md index aa9e0cc..f172158 100644 --- a/docs/guides/installation.md +++ b/docs/guides/installation.md @@ -23,7 +23,7 @@ No extra steps are required for **Android, iOS, macOS, Windows, or Linux**; the For **Flutter web**, you must add two assets and include a script: -1. Copy **zstd.js** and **zstd.wasm** from the [zstandard_web](https://github.com/landamessenger/zstandard/tree/master/zstandard_web) package (e.g. from its `blob/` or as documented there) into your app’s **web/** directory (e.g. `web/zstd.js`, `web/zstd.wasm`). +1. Copy **zstd.js** and **zstd.wasm** from the [zstandard_web](https://github.com/vypdev/zstandard/tree/master/zstandard_web) package (e.g. from its `blob/` or as documented there) into your app’s **web/** directory (e.g. `web/zstd.js`, `web/zstd.wasm`). 2. In **web/index.html**, include the script before your app loads: diff --git a/docs/platforms/web.md b/docs/platforms/web.md index cedc54f..3e986a3 100644 --- a/docs/platforms/web.md +++ b/docs/platforms/web.md @@ -76,7 +76,7 @@ If you need to rebuild the WebAssembly artifacts: - Exported functions: `ZSTD_compress`, `ZSTD_decompress`, `ZSTD_compressBound`, `ZSTD_getFrameContentSize`, `malloc`, `free` 4. Add the wrapper functions `compressData` and `decompressData` in `zstd.js` (or a separate script) that allocate buffers, call the C functions, and return the result or null. -Detailed commands and wrapper code are in the [zstandard_web README](https://github.com/landamessenger/zstandard/tree/master/zstandard_web). +Detailed commands and wrapper code are in the [zstandard_web README](https://github.com/vypdev/zstandard/tree/master/zstandard_web). ## Small Data Behavior diff --git a/scripts/build_web_wasm.sh b/scripts/build_web_wasm.sh index 3e56da2..f3a096c 100755 --- a/scripts/build_web_wasm.sh +++ b/scripts/build_web_wasm.sh @@ -16,6 +16,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ZSTD_ROOT="$ROOT/zstd" OUT_BLOB="$ROOT/zstandard_web/blob" OUT_EXAMPLE_WEB="$ROOT/zstandard_web/example/web" +OUT_ZSTANDARD_EXAMPLE_WEB="$ROOT/zstandard/example/web" if [[ ! -d "$ZSTD_ROOT" || ! -f "$ZSTD_ROOT/zstd.h" ]]; then echo "Error: Canonical zstd source not found at $ZSTD_ROOT (expected zstd.h)." @@ -51,6 +52,9 @@ emcc -O3 \ -s EXPORT_NAME="zstdWasmModule" \ -s EXPORTED_FUNCTIONS="['_ZSTD_compress','_ZSTD_decompress','_malloc','_free','_ZSTD_getFrameContentSize','_ZSTD_compressBound']" \ -s EXPORTED_RUNTIME_METHODS="['HEAPU8']" \ + -s INITIAL_MEMORY=134217728 \ + -s ALLOW_MEMORY_GROWTH=1 \ + -s MAXIMUM_MEMORY=2147483648 \ -o zstd_generated.js if [[ ! -f zstd_generated.js || ! -f zstd_generated.wasm ]]; then @@ -61,20 +65,37 @@ fi # Append the compressData/decompressData wrappers required by the web plugin (see zstandard_web/README.md). cat >> zstd_generated.js << 'WRAPPER_JS' -function compressData(inputData, compressionLevel) { +// Promise that resolves when the module is ready +let moduleReady = new Promise((resolve) => { + if (typeof Module !== 'undefined' && Module.calledRun) { + // Module already initialized + resolve(); + } else { + // Wait for module initialization + const originalOnRuntimeInitialized = Module.onRuntimeInitialized || function() {}; + Module.onRuntimeInitialized = function() { + originalOnRuntimeInitialized(); + resolve(); + }; + } +}); + +async function compressData(inputData, compressionLevel) { + await moduleReady; + let inputPtr = Module._malloc(inputData.length); Module.HEAPU8.set(inputData, inputPtr); - let outputBufferSize = Module._ZSTD_compressBound(inputData.length); + let outputBufferSize = Number(Module._ZSTD_compressBound(inputData.length)); let outputPtr = Module._malloc(outputBufferSize); - let compressedSize = Module._ZSTD_compress( + let compressedSize = Number(Module._ZSTD_compress( outputPtr, outputBufferSize, inputPtr, inputData.length, compressionLevel - ); + )); if (compressedSize < 0) { console.error('Compression error, error code: ', compressedSize); @@ -90,11 +111,13 @@ function compressData(inputData, compressionLevel) { } } -function decompressData(compressedData) { +async function decompressData(compressedData) { + await moduleReady; + let compressedPtr = Module._malloc(compressedData.length); Module.HEAPU8.set(compressedData, compressedPtr); - let decompressedSize = Module._ZSTD_getFrameContentSize(compressedPtr, compressedData.length); + let decompressedSize = Number(Module._ZSTD_getFrameContentSize(compressedPtr, compressedData.length)); if (decompressedSize === -1 || decompressedSize === -2) { console.error('Error in obtaining the original size of the data'); Module._free(compressedPtr); @@ -103,12 +126,12 @@ function decompressData(compressedData) { let decompressedPtr = Module._malloc(decompressedSize); - let resultSize = Module._ZSTD_decompress( + let resultSize = Number(Module._ZSTD_decompress( decompressedPtr, decompressedSize, compressedPtr, compressedData.length - ); + )); if (resultSize < 0) { console.error('Decompression error, error code: ', resultSize); @@ -125,14 +148,22 @@ function decompressData(compressedData) { } WRAPPER_JS -mkdir -p "$OUT_BLOB" "$OUT_EXAMPLE_WEB" +mkdir -p "$OUT_BLOB" "$OUT_EXAMPLE_WEB" "$OUT_ZSTANDARD_EXAMPLE_WEB" + +# Replace the wasm filename in the generated JS to match what we'll copy +sed -i.bak 's/zstd_generated\.wasm/zstd.wasm/g' zstd_generated.js +rm -f zstd_generated.js.bak + cp zstd_generated.wasm "$OUT_BLOB/zstd.wasm" cp zstd_generated.wasm "$OUT_EXAMPLE_WEB/zstd.wasm" +cp zstd_generated.wasm "$OUT_ZSTANDARD_EXAMPLE_WEB/zstd.wasm" cp zstd_generated.js "$OUT_BLOB/zstd.js" cp zstd_generated.js "$OUT_EXAMPLE_WEB/zstd.js" +cp zstd_generated.js "$OUT_ZSTANDARD_EXAMPLE_WEB/zstd.js" rm -f "$ZSTD_ROOT/zstd_generated.js" "$ZSTD_ROOT/zstd_generated.wasm" echo "Done. zstd.js and zstd.wasm have been written to:" echo " - $OUT_BLOB/" echo " - $OUT_EXAMPLE_WEB/" +echo " - $OUT_ZSTANDARD_EXAMPLE_WEB/" echo "Built from the same zstd/ source used by Android, iOS, macOS, Windows, Linux, and CLI." diff --git a/zstandard/CHANGELOG.md b/zstandard/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard/CHANGELOG.md +++ b/zstandard/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard/README.md b/zstandard/README.md index 06d4a8c..374a6bc 100644 --- a/zstandard/README.md +++ b/zstandard/README.md @@ -44,14 +44,14 @@ void act() async { Below are examples of the plugin in action across different platforms. -

+

-

+

-

+

-

+

-

+

-

+

diff --git a/zstandard/example/web/zstd.js b/zstandard/example/web/zstd.js index c23fe55..9d831c9 100644 --- a/zstandard/example/web/zstd.js +++ b/zstandard/example/web/zstd.js @@ -1,39 +1,58 @@ -var Module=typeof zstdWasmModule!="undefined"?zstdWasmModule:{};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&process.type!="renderer";if(ENVIRONMENT_IS_NODE){}var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);var ret=fs.readFileSync(filename);return ret};readAsync=(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);return new Promise((resolve,reject)=>{fs.readFile(filename,binary?undefined:"utf8",(err,data)=>{if(err)reject(err);else resolve(binary?data.buffer:data)})})};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}return fetch(url,{credentials:"same-origin"}).then(response=>{if(response.ok){return response.arrayBuffer()}return Promise.reject(new Error(response.status+" : "+response.url))})}}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){var preRuns=Module["preRun"];if(preRuns){if(typeof preRuns=="function")preRuns=[preRuns];preRuns.forEach(addOnPreRun)}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function postRun(){var postRuns=Module["postRun"];if(postRuns){if(typeof postRuns=="function")postRuns=[postRuns];postRuns.forEach(addOnPostRun)}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");function findWasmBinary(){var f="zstd.wasm";if(!isDataURI(f)){return locateFile(f)}return f}var wasmBinaryFile;function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}function getBinaryPromise(binaryFile){if(!wasmBinary){return readAsync(binaryFile).then(response=>new Uint8Array(response),()=>getBinarySync(binaryFile))}return Promise.resolve().then(()=>getBinarySync(binaryFile))}function instantiateArrayBuffer(binaryFile,imports,receiver){return getBinaryPromise(binaryFile).then(binary=>WebAssembly.instantiate(binary,imports)).then(receiver,reason=>{err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)})}function instantiateAsync(binary,binaryFile,imports,callback){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{var result=WebAssembly.instantiateStreaming(response,imports);return result.then(callback,function(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(binaryFile,imports,callback)})})}return instantiateArrayBuffer(binaryFile,imports,callback)}function getWasmImports(){return{a:wasmImports}}function createWasm(){var info=getWasmImports();function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["c"];updateMemoryViews();addOnInit(wasmExports["d"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);return false}}wasmBinaryFile??=findWasmBinary();instantiateAsync(wasmBinary,wasmBinaryFile,info,receiveInstantiationResult);return{}}var callRuntimeCallbacks=callbacks=>{callbacks.forEach(f=>f(Module))};var noExitRuntime=Module["noExitRuntime"]||true;var __emscripten_memcpy_js=(dest,src,num)=>HEAPU8.copyWithin(dest,src,src+num);var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;abortOnCannotGrowMemory(requestedSize)};var wasmImports={b:__emscripten_memcpy_js,a:_emscripten_resize_heap};var wasmExports=createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["d"])();var _free=Module["_free"]=a0=>(_free=Module["_free"]=wasmExports["f"])(a0);var _ZSTD_compressBound=Module["_ZSTD_compressBound"]=a0=>(_ZSTD_compressBound=Module["_ZSTD_compressBound"]=wasmExports["g"])(a0);var _malloc=Module["_malloc"]=a0=>(_malloc=Module["_malloc"]=wasmExports["h"])(a0);var _ZSTD_compress=Module["_ZSTD_compress"]=(a0,a1,a2,a3,a4)=>(_ZSTD_compress=Module["_ZSTD_compress"]=wasmExports["i"])(a0,a1,a2,a3,a4);var _ZSTD_getFrameContentSize=Module["_ZSTD_getFrameContentSize"]=(a0,a1)=>(_ZSTD_getFrameContentSize=Module["_ZSTD_getFrameContentSize"]=wasmExports["j"])(a0,a1);var _ZSTD_decompress=Module["_ZSTD_decompress"]=(a0,a1,a2,a3)=>(_ZSTD_decompress=Module["_ZSTD_decompress"]=wasmExports["k"])(a0,a1,a2,a3);var calledRun;var calledPrerun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function run(){if(runDependencies>0){return}if(!calledPrerun){calledPrerun=1;preRun();if(runDependencies>0){return}}function doRun(){if(calledRun)return;calledRun=1;Module["calledRun"]=1;if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run(); +var Module=typeof zstdWasmModule!="undefined"?zstdWasmModule:{};var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=globalThis.document?.currentScript?.src;if(typeof __filename!="undefined"){_scriptName=__filename}else if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["c"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("zstd.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var runDependencies=0;var dependenciesFulfilled=null;var removeRunDependency=id=>{runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}};var addRunDependency=id=>{runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)};var noExitRuntime=true;var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}var _malloc,_free,_ZSTD_compressBound,_ZSTD_compress,_ZSTD_getFrameContentSize,_ZSTD_decompress,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_malloc=Module["_malloc"]=wasmExports["d"];_free=Module["_free"]=wasmExports["e"];_ZSTD_compressBound=Module["_ZSTD_compressBound"]=wasmExports["f"];_ZSTD_compress=Module["_ZSTD_compress"]=wasmExports["g"];_ZSTD_getFrameContentSize=Module["_ZSTD_getFrameContentSize"]=wasmExports["h"];_ZSTD_decompress=Module["_ZSTD_decompress"]=wasmExports["i"];memory=wasmMemory=wasmExports["b"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={a:_emscripten_resize_heap};function run(){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;createWasm();run(); -function compressData(inputData, compressionLevel) { +// Promise that resolves when the module is ready +let moduleReady = new Promise((resolve) => { + if (typeof Module !== 'undefined' && Module.calledRun) { + // Module already initialized + resolve(); + } else { + // Wait for module initialization + const originalOnRuntimeInitialized = Module.onRuntimeInitialized || function() {}; + Module.onRuntimeInitialized = function() { + originalOnRuntimeInitialized(); + resolve(); + }; + } +}); + +async function compressData(inputData, compressionLevel) { + await moduleReady; + let inputPtr = Module._malloc(inputData.length); Module.HEAPU8.set(inputData, inputPtr); - let outputBufferSize = Module._ZSTD_compressBound(inputData.length); + let outputBufferSize = Number(Module._ZSTD_compressBound(inputData.length)); let outputPtr = Module._malloc(outputBufferSize); - let compressedSize = Module._ZSTD_compress( + let compressedSize = Number(Module._ZSTD_compress( outputPtr, outputBufferSize, inputPtr, inputData.length, compressionLevel - ); + )); if (compressedSize < 0) { console.error('Compression error, error code: ', compressedSize); + Module._free(inputPtr); + Module._free(outputPtr); return null; } else { let compressedData = new Uint8Array(Module.HEAPU8.buffer, outputPtr, compressedSize); let out = compressedData.slice(0); - Module._free(inputPtr); Module._free(outputPtr); - return out; } } -function decompressData(compressedData) { +async function decompressData(compressedData) { + await moduleReady; + let compressedPtr = Module._malloc(compressedData.length); Module.HEAPU8.set(compressedData, compressedPtr); - let decompressedSize = Module._ZSTD_getFrameContentSize(compressedPtr, compressedData.length); + let decompressedSize = Number(Module._ZSTD_getFrameContentSize(compressedPtr, compressedData.length)); if (decompressedSize === -1 || decompressedSize === -2) { console.error('Error in obtaining the original size of the data'); Module._free(compressedPtr); @@ -42,12 +61,12 @@ function decompressData(compressedData) { let decompressedPtr = Module._malloc(decompressedSize); - let resultSize = Module._ZSTD_decompress( + let resultSize = Number(Module._ZSTD_decompress( decompressedPtr, decompressedSize, compressedPtr, compressedData.length - ); + )); if (resultSize < 0) { console.error('Decompression error, error code: ', resultSize); @@ -57,10 +76,8 @@ function decompressData(compressedData) { } else { let decompressedData = new Uint8Array(Module.HEAPU8.buffer, decompressedPtr, resultSize); let out = decompressedData.slice(0); - Module._free(compressedPtr); Module._free(decompressedPtr); - return out; } } diff --git a/zstandard/example/web/zstd.wasm b/zstandard/example/web/zstd.wasm index d64eacb..ef8535b 100755 Binary files a/zstandard/example/web/zstd.wasm and b/zstandard/example/web/zstd.wasm differ diff --git a/zstandard/pubspec.yaml b/zstandard/pubspec.yaml index 626836c..54a07c4 100644 --- a/zstandard/pubspec.yaml +++ b/zstandard/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard description: "Flutter plugin to implement Zstandard compression" -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard environment: sdk: ^3.6.0 @@ -28,13 +28,13 @@ flutter: dependencies: flutter: sdk: flutter - zstandard_android: ^1.3.32 - zstandard_ios: ^1.3.32 - zstandard_linux: ^1.3.32 - zstandard_macos: ^1.3.32 - zstandard_platform_interface: ^1.3.32 - zstandard_web: ^1.3.32 - zstandard_windows: ^1.3.32 + zstandard_android: ^1.4.0 + zstandard_ios: ^1.4.0 + zstandard_linux: ^1.4.0 + zstandard_macos: ^1.4.0 + zstandard_platform_interface: ^1.4.0 + zstandard_web: ^1.4.0 + zstandard_windows: ^1.4.0 dev_dependencies: flutter_lints: ^6.0.0 diff --git a/zstandard_android/CHANGELOG.md b/zstandard_android/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard_android/CHANGELOG.md +++ b/zstandard_android/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard_android/README.md b/zstandard_android/README.md index a558a9a..eb5143c 100644 --- a/zstandard_android/README.md +++ b/zstandard_android/README.md @@ -64,6 +64,6 @@ Unit tests run only on Android (they are skipped on other platforms). For full i - **Library not found**: Ensure you build and run the app for Android (e.g. `flutter run` or `flutter build apk`) so the native library is compiled and packaged. - **Crashes**: Verify inputs are non-null and valid; for decompress, ensure the data is a valid zstd frame. -See the [documentation](https://github.com/landamessenger/zstandard/tree/master/docs) for more. +See the [documentation](https://github.com/vypdev/zstandard/tree/master/docs) for more. -

+

diff --git a/zstandard_android/android/build.gradle b/zstandard_android/android/build.gradle index 4212247..f0a2118 100644 --- a/zstandard_android/android/build.gradle +++ b/zstandard_android/android/build.gradle @@ -1,6 +1,6 @@ // The Android Gradle Plugin builds the native code with the Android NDK. -group = "com.landamessenger.zstandard_android" +group = "dev.vyp.zstandard_android" version = "1.0" buildscript { @@ -29,7 +29,7 @@ apply plugin: "kotlin-android" android { if (project.android.hasProperty("namespace")) { - namespace = "com.landamessenger.zstandard_android" + namespace = "dev.vyp.zstandard_android" } // Bumping the plugin compileSdk version requires all clients of this plugin diff --git a/zstandard_android/android/src/androidTest/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidComprehensiveTest.kt b/zstandard_android/android/src/androidTest/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidComprehensiveTest.kt index 4bfea31..3147a46 100644 --- a/zstandard_android/android/src/androidTest/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidComprehensiveTest.kt +++ b/zstandard_android/android/src/androidTest/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidComprehensiveTest.kt @@ -1,4 +1,4 @@ -package com.landamessenger.zstandard_android +package dev.vyp.zstandard_android import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 diff --git a/zstandard_android/android/src/androidTest/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidInstrumentedTest.kt b/zstandard_android/android/src/androidTest/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidInstrumentedTest.kt index 7b40c21..ba40d02 100644 --- a/zstandard_android/android/src/androidTest/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidInstrumentedTest.kt +++ b/zstandard_android/android/src/androidTest/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidInstrumentedTest.kt @@ -1,4 +1,4 @@ -package com.landamessenger.zstandard_android +package dev.vyp.zstandard_android import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 diff --git a/zstandard_android/android/src/main/AndroidManifest.xml b/zstandard_android/android/src/main/AndroidManifest.xml index 93e26cd..39df1e4 100644 --- a/zstandard_android/android/src/main/AndroidManifest.xml +++ b/zstandard_android/android/src/main/AndroidManifest.xml @@ -1,3 +1,3 @@ + package="dev.vyp.zstandard_android"> diff --git a/zstandard_android/android/src/main/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidPlugin.kt b/zstandard_android/android/src/main/kotlin/dev/vyp/zstandard_android/ZstandardAndroidPlugin.kt similarity index 96% rename from zstandard_android/android/src/main/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidPlugin.kt rename to zstandard_android/android/src/main/kotlin/dev/vyp/zstandard_android/ZstandardAndroidPlugin.kt index b169439..d7f2499 100644 --- a/zstandard_android/android/src/main/kotlin/com/landamessenger/zstandard_android/ZstandardAndroidPlugin.kt +++ b/zstandard_android/android/src/main/kotlin/dev/vyp/zstandard_android/ZstandardAndroidPlugin.kt @@ -1,4 +1,4 @@ -package com.landamessenger.zstandard_android +package dev.vyp.zstandard_android import androidx.annotation.NonNull diff --git a/zstandard_android/example/android/app/build.gradle b/zstandard_android/example/android/app/build.gradle index 75360eb..3c20fe4 100644 --- a/zstandard_android/example/android/app/build.gradle +++ b/zstandard_android/example/android/app/build.gradle @@ -6,7 +6,7 @@ plugins { } android { - namespace = "com.landamessenger.zstandard_android_example" + namespace = "dev.vyp.zstandard_android_example" compileSdk = flutter.compileSdkVersion ndkVersion = flutter.ndkVersion @@ -21,7 +21,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId = "com.landamessenger.zstandard_android_example" + applicationId = "dev.vyp.zstandard_android_example" // You can update the following values to match your application needs. // For more information, see: https://flutter.dev/to/review-gradle-config. minSdk = flutter.minSdkVersion diff --git a/zstandard_android/example/android/app/src/main/kotlin/com/landamessenger/zstandard_android_example/MainActivity.kt b/zstandard_android/example/android/app/src/main/kotlin/dev/vyp/zstandard_android_example/MainActivity.kt similarity index 63% rename from zstandard_android/example/android/app/src/main/kotlin/com/landamessenger/zstandard_android_example/MainActivity.kt rename to zstandard_android/example/android/app/src/main/kotlin/dev/vyp/zstandard_android_example/MainActivity.kt index 3f481b5..127fbb1 100644 --- a/zstandard_android/example/android/app/src/main/kotlin/com/landamessenger/zstandard_android_example/MainActivity.kt +++ b/zstandard_android/example/android/app/src/main/kotlin/dev/vyp/zstandard_android_example/MainActivity.kt @@ -1,4 +1,4 @@ -package com.landamessenger.zstandard_android_example +package dev.vyp.zstandard_android_example import io.flutter.embedding.android.FlutterActivity diff --git a/zstandard_android/pubspec.yaml b/zstandard_android/pubspec.yaml index 8b2b39f..b431be4 100644 --- a/zstandard_android/pubspec.yaml +++ b/zstandard_android/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard_android description: Android platform implementation of zstandard -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard/tree/master/zstandard_android +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard/tree/master/zstandard_android environment: sdk: ^3.6.0 @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - zstandard_platform_interface: ^1.3.32 + zstandard_platform_interface: ^1.4.0 ffi: ^2.1.3 dev_dependencies: @@ -29,6 +29,6 @@ flutter: plugin: platforms: android: - package: com.landamessenger.zstandard_android + package: dev.vyp.zstandard_android pluginClass: ZstandardAndroidPlugin ffiPlugin: true diff --git a/zstandard_cli/CHANGELOG.md b/zstandard_cli/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard_cli/CHANGELOG.md +++ b/zstandard_cli/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard_cli/README.md b/zstandard_cli/README.md index 451634a..cc2e456 100644 --- a/zstandard_cli/README.md +++ b/zstandard_cli/README.md @@ -76,15 +76,15 @@ Tests run only on supported platforms (macOS, Windows, Linux). They cover small/ - **Library not found**: Ensure you are on macOS, Windows, or Linux (x64 or arm64). Update the package with `dart pub upgrade zstandard_cli`. - **Compress/decompress returns null**: Check that input is valid; for decompress, ensure the data is a complete zstd frame. -See the [documentation](https://github.com/landamessenger/zstandard/tree/master/docs) for more. +See the [documentation](https://github.com/vypdev/zstandard/tree/master/docs) for more. --- The images provided below illustrate how to use `zstandard_cli` for compression and decompression on different platforms. -

-

-

-

-

-

+

+

+

+

+

+

diff --git a/zstandard_cli/lib/src/bin/zstandard_windows_arm64.dll b/zstandard_cli/lib/src/bin/zstandard_windows_arm64.dll index 67a97f0..4289351 100644 Binary files a/zstandard_cli/lib/src/bin/zstandard_windows_arm64.dll and b/zstandard_cli/lib/src/bin/zstandard_windows_arm64.dll differ diff --git a/zstandard_cli/lib/src/bin/zstandard_windows_x64.dll b/zstandard_cli/lib/src/bin/zstandard_windows_x64.dll index a99120f..9a3a372 100644 Binary files a/zstandard_cli/lib/src/bin/zstandard_windows_x64.dll and b/zstandard_cli/lib/src/bin/zstandard_windows_x64.dll differ diff --git a/zstandard_cli/pubspec.yaml b/zstandard_cli/pubspec.yaml index add5e1d..636491c 100644 --- a/zstandard_cli/pubspec.yaml +++ b/zstandard_cli/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard_cli description: CLI implementation of zstandard. For desktops. -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard/tree/master/zstandard_cli +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard/tree/master/zstandard_cli environment: sdk: ^3.6.0 diff --git a/zstandard_ios/CHANGELOG.md b/zstandard_ios/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard_ios/CHANGELOG.md +++ b/zstandard_ios/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard_ios/README.md b/zstandard_ios/README.md index b0f64a6..fdc43dd 100644 --- a/zstandard_ios/README.md +++ b/zstandard_ios/README.md @@ -64,6 +64,6 @@ Unit tests run only on iOS (skipped on other platforms). For integration tests, - **Symbol or framework not found**: Ensure the iOS target is built (e.g. `flutter run -d ios`) and that you are targeting a supported architecture (arm64 device, x86_64/arm64 simulator). - **CocoaPods**: Run `pod install` in your app’s `ios/` directory if needed. -See the [documentation](https://github.com/landamessenger/zstandard/tree/master/docs) for more. +See the [documentation](https://github.com/vypdev/zstandard/tree/master/docs) for more. -

+

diff --git a/zstandard_ios/pubspec.yaml b/zstandard_ios/pubspec.yaml index 1da9179..68eb43d 100644 --- a/zstandard_ios/pubspec.yaml +++ b/zstandard_ios/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard_ios description: iOS platform implementation of zstandard -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard/tree/master/zstandard_ios +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard/tree/master/zstandard_ios environment: sdk: ^3.6.0 @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - zstandard_platform_interface: ^1.3.32 + zstandard_platform_interface: ^1.4.0 ffi: ^2.1.3 dev_dependencies: diff --git a/zstandard_linux/CHANGELOG.md b/zstandard_linux/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard_linux/CHANGELOG.md +++ b/zstandard_linux/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard_linux/README.md b/zstandard_linux/README.md index acbe362..3c9052b 100644 --- a/zstandard_linux/README.md +++ b/zstandard_linux/README.md @@ -64,6 +64,6 @@ Unit tests run only on Linux (skipped on other platforms). For integration tests - **libzstandard_linux_plugin.so not found**: Build your app with `flutter build linux` or run from the Flutter Linux runner so the native library is built and available. - **Crashes**: Verify inputs and that you are on a supported architecture (x64 or arm64). -See the [documentation](https://github.com/landamessenger/zstandard/tree/master/docs) for more. +See the [documentation](https://github.com/vypdev/zstandard/tree/master/docs) for more. -

+

diff --git a/zstandard_linux/example/linux/CMakeLists.txt b/zstandard_linux/example/linux/CMakeLists.txt index 5b03c1c..af714c9 100644 --- a/zstandard_linux/example/linux/CMakeLists.txt +++ b/zstandard_linux/example/linux/CMakeLists.txt @@ -7,7 +7,7 @@ project(runner LANGUAGES CXX) set(BINARY_NAME "zstandard_linux_example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID -set(APPLICATION_ID "com.landamessenger.zstandard.zstandard_linux") +set(APPLICATION_ID "dev.vyp.zstandard.zstandard_linux") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. diff --git a/zstandard_linux/pubspec.yaml b/zstandard_linux/pubspec.yaml index 03a2bf8..95b6d41 100644 --- a/zstandard_linux/pubspec.yaml +++ b/zstandard_linux/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard_linux description: Linux platform implementation of zstandard -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard/tree/master/zstandard_linux +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard/tree/master/zstandard_linux environment: sdk: ^3.6.0 @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - zstandard_platform_interface: ^1.3.32 + zstandard_platform_interface: ^1.4.0 ffi: ^2.1.3 dev_dependencies: diff --git a/zstandard_macos/CHANGELOG.md b/zstandard_macos/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard_macos/CHANGELOG.md +++ b/zstandard_macos/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard_macos/README.md b/zstandard_macos/README.md index baa88be..9262f68 100644 --- a/zstandard_macos/README.md +++ b/zstandard_macos/README.md @@ -64,6 +64,6 @@ Unit tests that use the native library require the framework to be built (e.g. b - **Library not loaded**: Build your app with `flutter build macos` or run from the macOS runner so the framework is built and linked. - **Wrong architecture**: Ensure you are building for the correct target (x64 vs arm64). -See the [documentation](https://github.com/landamessenger/zstandard/tree/master/docs) for more. +See the [documentation](https://github.com/vypdev/zstandard/tree/master/docs) for more. -

+

diff --git a/zstandard_macos/pubspec.yaml b/zstandard_macos/pubspec.yaml index 8ece3ab..d912892 100644 --- a/zstandard_macos/pubspec.yaml +++ b/zstandard_macos/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard_macos description: macOS platform implementation of zstandard -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard/tree/master/zstandard_macos +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard/tree/master/zstandard_macos environment: sdk: ^3.6.0 @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - zstandard_platform_interface: ^1.3.32 + zstandard_platform_interface: ^1.4.0 ffi: ^2.1.3 dev_dependencies: diff --git a/zstandard_platform_interface/CHANGELOG.md b/zstandard_platform_interface/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard_platform_interface/CHANGELOG.md +++ b/zstandard_platform_interface/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard_platform_interface/pubspec.yaml b/zstandard_platform_interface/pubspec.yaml index 1f02b0c..5d4449d 100644 --- a/zstandard_platform_interface/pubspec.yaml +++ b/zstandard_platform_interface/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard_platform_interface description: A common platform interface for the zstandard plugin. -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard/tree/master/zstandard_platform_interface +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard/tree/master/zstandard_platform_interface environment: sdk: ^3.6.0 diff --git a/zstandard_web/CHANGELOG.md b/zstandard_web/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard_web/CHANGELOG.md +++ b/zstandard_web/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard_web/README.md b/zstandard_web/README.md index 87cafaf..1e4c533 100644 --- a/zstandard_web/README.md +++ b/zstandard_web/README.md @@ -33,7 +33,7 @@ void act() async { } ``` -

+

## Generation @@ -170,4 +170,4 @@ Unit tests run only on web (skipped on other platforms). Full integration tests - **compressData / decompressData is not defined**: Ensure `zstd.js` is included in your `web/index.html` and loads before the Flutter app. - **WASM load failed**: Ensure `zstd.wasm` is served from the same origin and the path is correct. Check the browser console and network tab. -See the [documentation](https://github.com/landamessenger/zstandard/tree/master/docs) for more. +See the [documentation](https://github.com/vypdev/zstandard/tree/master/docs) for more. diff --git a/zstandard_web/blob/zstd.js b/zstandard_web/blob/zstd.js index 24a5563..9d831c9 100644 --- a/zstandard_web/blob/zstd.js +++ b/zstandard_web/blob/zstd.js @@ -1,19 +1,36 @@ -var Module=typeof zstdWasmModule!="undefined"?zstdWasmModule:{};var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=globalThis.document?.currentScript?.src;if(typeof __filename!="undefined"){_scriptName=__filename}else if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["c"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("zstd_generated.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var runDependencies=0;var dependenciesFulfilled=null;var removeRunDependency=id=>{runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}};var addRunDependency=id=>{runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)};var noExitRuntime=true;var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;abortOnCannotGrowMemory(requestedSize)};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}var _malloc,_free,_ZSTD_compressBound,_ZSTD_compress,_ZSTD_getFrameContentSize,_ZSTD_decompress,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_malloc=Module["_malloc"]=wasmExports["d"];_free=Module["_free"]=wasmExports["e"];_ZSTD_compressBound=Module["_ZSTD_compressBound"]=wasmExports["f"];_ZSTD_compress=Module["_ZSTD_compress"]=wasmExports["g"];_ZSTD_getFrameContentSize=Module["_ZSTD_getFrameContentSize"]=wasmExports["h"];_ZSTD_decompress=Module["_ZSTD_decompress"]=wasmExports["i"];memory=wasmMemory=wasmExports["b"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={a:_emscripten_resize_heap};function run(){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;createWasm();run(); +var Module=typeof zstdWasmModule!="undefined"?zstdWasmModule:{};var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=globalThis.document?.currentScript?.src;if(typeof __filename!="undefined"){_scriptName=__filename}else if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["c"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("zstd.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var runDependencies=0;var dependenciesFulfilled=null;var removeRunDependency=id=>{runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}};var addRunDependency=id=>{runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)};var noExitRuntime=true;var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}var _malloc,_free,_ZSTD_compressBound,_ZSTD_compress,_ZSTD_getFrameContentSize,_ZSTD_decompress,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_malloc=Module["_malloc"]=wasmExports["d"];_free=Module["_free"]=wasmExports["e"];_ZSTD_compressBound=Module["_ZSTD_compressBound"]=wasmExports["f"];_ZSTD_compress=Module["_ZSTD_compress"]=wasmExports["g"];_ZSTD_getFrameContentSize=Module["_ZSTD_getFrameContentSize"]=wasmExports["h"];_ZSTD_decompress=Module["_ZSTD_decompress"]=wasmExports["i"];memory=wasmMemory=wasmExports["b"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={a:_emscripten_resize_heap};function run(){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;createWasm();run(); -function compressData(inputData, compressionLevel) { +// Promise that resolves when the module is ready +let moduleReady = new Promise((resolve) => { + if (typeof Module !== 'undefined' && Module.calledRun) { + // Module already initialized + resolve(); + } else { + // Wait for module initialization + const originalOnRuntimeInitialized = Module.onRuntimeInitialized || function() {}; + Module.onRuntimeInitialized = function() { + originalOnRuntimeInitialized(); + resolve(); + }; + } +}); + +async function compressData(inputData, compressionLevel) { + await moduleReady; + let inputPtr = Module._malloc(inputData.length); Module.HEAPU8.set(inputData, inputPtr); - let outputBufferSize = Module._ZSTD_compressBound(inputData.length); + let outputBufferSize = Number(Module._ZSTD_compressBound(inputData.length)); let outputPtr = Module._malloc(outputBufferSize); - let compressedSize = Module._ZSTD_compress( + let compressedSize = Number(Module._ZSTD_compress( outputPtr, outputBufferSize, inputPtr, inputData.length, compressionLevel - ); + )); if (compressedSize < 0) { console.error('Compression error, error code: ', compressedSize); @@ -29,11 +46,13 @@ function compressData(inputData, compressionLevel) { } } -function decompressData(compressedData) { +async function decompressData(compressedData) { + await moduleReady; + let compressedPtr = Module._malloc(compressedData.length); Module.HEAPU8.set(compressedData, compressedPtr); - let decompressedSize = Module._ZSTD_getFrameContentSize(compressedPtr, compressedData.length); + let decompressedSize = Number(Module._ZSTD_getFrameContentSize(compressedPtr, compressedData.length)); if (decompressedSize === -1 || decompressedSize === -2) { console.error('Error in obtaining the original size of the data'); Module._free(compressedPtr); @@ -42,12 +61,12 @@ function decompressData(compressedData) { let decompressedPtr = Module._malloc(decompressedSize); - let resultSize = Module._ZSTD_decompress( + let resultSize = Number(Module._ZSTD_decompress( decompressedPtr, decompressedSize, compressedPtr, compressedData.length - ); + )); if (resultSize < 0) { console.error('Decompression error, error code: ', resultSize); diff --git a/zstandard_web/blob/zstd.wasm b/zstandard_web/blob/zstd.wasm index 256ba34..ef8535b 100755 Binary files a/zstandard_web/blob/zstd.wasm and b/zstandard_web/blob/zstd.wasm differ diff --git a/zstandard_web/example/integration_test/zstandard_web_integration_test.dart b/zstandard_web/example/integration_test/zstandard_web_integration_test.dart index a3e6749..86bb4d7 100644 --- a/zstandard_web/example/integration_test/zstandard_web_integration_test.dart +++ b/zstandard_web/example/integration_test/zstandard_web_integration_test.dart @@ -35,11 +35,14 @@ void main() { expect(version, isNotNull); }); - test('compress returns the same data if length is less than 9 bytes', + test('compress and decompress roundtrip for data shorter than 9 bytes', () async { final data = Uint8List.fromList([1, 2, 3, 4, 5]); - final result = await zstandardWeb.compress(data, 3); - expect(result, data); + final compressed = await zstandardWeb.compress(data, 3); + expect(compressed, isNotNull); + final decompressed = + await zstandardWeb.decompress(compressed ?? Uint8List(0)); + expect(decompressed, equals(data)); }); test('compress and decompress small data', () async { diff --git a/zstandard_web/example/web/zstd.js b/zstandard_web/example/web/zstd.js index 24a5563..9d831c9 100644 --- a/zstandard_web/example/web/zstd.js +++ b/zstandard_web/example/web/zstd.js @@ -1,19 +1,36 @@ -var Module=typeof zstdWasmModule!="undefined"?zstdWasmModule:{};var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=globalThis.document?.currentScript?.src;if(typeof __filename!="undefined"){_scriptName=__filename}else if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["c"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("zstd_generated.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var runDependencies=0;var dependenciesFulfilled=null;var removeRunDependency=id=>{runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}};var addRunDependency=id=>{runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)};var noExitRuntime=true;var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;abortOnCannotGrowMemory(requestedSize)};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}var _malloc,_free,_ZSTD_compressBound,_ZSTD_compress,_ZSTD_getFrameContentSize,_ZSTD_decompress,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_malloc=Module["_malloc"]=wasmExports["d"];_free=Module["_free"]=wasmExports["e"];_ZSTD_compressBound=Module["_ZSTD_compressBound"]=wasmExports["f"];_ZSTD_compress=Module["_ZSTD_compress"]=wasmExports["g"];_ZSTD_getFrameContentSize=Module["_ZSTD_getFrameContentSize"]=wasmExports["h"];_ZSTD_decompress=Module["_ZSTD_decompress"]=wasmExports["i"];memory=wasmMemory=wasmExports["b"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={a:_emscripten_resize_heap};function run(){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;createWasm();run(); +var Module=typeof zstdWasmModule!="undefined"?zstdWasmModule:{};var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=globalThis.document?.currentScript?.src;if(typeof __filename!="undefined"){_scriptName=__filename}else if(ENVIRONMENT_IS_WORKER){_scriptName=self.location.href}var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var isFileURI=filename=>filename.startsWith("file://");var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;var HEAP64,HEAPU64;var runtimeInitialized=false;function updateMemoryViews(){var b=wasmMemory.buffer;HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["c"]()}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){return locateFile("zstd.wasm")}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){return new Promise((resolve,reject)=>{Module["instantiateWasm"](info,(inst,mod)=>{resolve(receiveInstance(inst,mod))})})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var addOnPostRun=cb=>onPostRuns.push(cb);var onPreRuns=[];var addOnPreRun=cb=>onPreRuns.push(cb);var runDependencies=0;var dependenciesFulfilled=null;var removeRunDependency=id=>{runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}};var addRunDependency=id=>{runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)};var noExitRuntime=true;var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].shift()()}}}var _malloc,_free,_ZSTD_compressBound,_ZSTD_compress,_ZSTD_getFrameContentSize,_ZSTD_decompress,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_malloc=Module["_malloc"]=wasmExports["d"];_free=Module["_free"]=wasmExports["e"];_ZSTD_compressBound=Module["_ZSTD_compressBound"]=wasmExports["f"];_ZSTD_compress=Module["_ZSTD_compress"]=wasmExports["g"];_ZSTD_getFrameContentSize=Module["_ZSTD_getFrameContentSize"]=wasmExports["h"];_ZSTD_decompress=Module["_ZSTD_decompress"]=wasmExports["i"];memory=wasmMemory=wasmExports["b"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={a:_emscripten_resize_heap};function run(){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}var wasmExports;createWasm();run(); -function compressData(inputData, compressionLevel) { +// Promise that resolves when the module is ready +let moduleReady = new Promise((resolve) => { + if (typeof Module !== 'undefined' && Module.calledRun) { + // Module already initialized + resolve(); + } else { + // Wait for module initialization + const originalOnRuntimeInitialized = Module.onRuntimeInitialized || function() {}; + Module.onRuntimeInitialized = function() { + originalOnRuntimeInitialized(); + resolve(); + }; + } +}); + +async function compressData(inputData, compressionLevel) { + await moduleReady; + let inputPtr = Module._malloc(inputData.length); Module.HEAPU8.set(inputData, inputPtr); - let outputBufferSize = Module._ZSTD_compressBound(inputData.length); + let outputBufferSize = Number(Module._ZSTD_compressBound(inputData.length)); let outputPtr = Module._malloc(outputBufferSize); - let compressedSize = Module._ZSTD_compress( + let compressedSize = Number(Module._ZSTD_compress( outputPtr, outputBufferSize, inputPtr, inputData.length, compressionLevel - ); + )); if (compressedSize < 0) { console.error('Compression error, error code: ', compressedSize); @@ -29,11 +46,13 @@ function compressData(inputData, compressionLevel) { } } -function decompressData(compressedData) { +async function decompressData(compressedData) { + await moduleReady; + let compressedPtr = Module._malloc(compressedData.length); Module.HEAPU8.set(compressedData, compressedPtr); - let decompressedSize = Module._ZSTD_getFrameContentSize(compressedPtr, compressedData.length); + let decompressedSize = Number(Module._ZSTD_getFrameContentSize(compressedPtr, compressedData.length)); if (decompressedSize === -1 || decompressedSize === -2) { console.error('Error in obtaining the original size of the data'); Module._free(compressedPtr); @@ -42,12 +61,12 @@ function decompressData(compressedData) { let decompressedPtr = Module._malloc(decompressedSize); - let resultSize = Module._ZSTD_decompress( + let resultSize = Number(Module._ZSTD_decompress( decompressedPtr, decompressedSize, compressedPtr, compressedData.length - ); + )); if (resultSize < 0) { console.error('Decompression error, error code: ', resultSize); diff --git a/zstandard_web/example/web/zstd.wasm b/zstandard_web/example/web/zstd.wasm index 256ba34..ef8535b 100755 Binary files a/zstandard_web/example/web/zstd.wasm and b/zstandard_web/example/web/zstd.wasm differ diff --git a/zstandard_web/lib/zstandard_web.dart b/zstandard_web/lib/zstandard_web.dart index c07ec86..09fb67f 100644 --- a/zstandard_web/lib/zstandard_web.dart +++ b/zstandard_web/lib/zstandard_web.dart @@ -37,11 +37,11 @@ class ZstandardWeb extends ZstandardPlatform { @override Future compress(Uint8List data, int compressionLevel) async { - if (data.length < 9) return data; - var compressedData = html.window.callMethodVarArgs('compressData'.toJS, [ + var promise = html.window.callMethodVarArgs('compressData'.toJS, [ data.toJS, compressionLevel.toJS, - ]) as JSUint8Array?; + ]) as JSPromise; + var compressedData = (await promise.toDart) as JSUint8Array?; if (compressedData != null) { return compressedData.toDart; } else { @@ -51,11 +51,10 @@ class ZstandardWeb extends ZstandardPlatform { @override Future decompress(Uint8List data) async { - if (data.length < 9) return data; - var decompressedData = - html.window.callMethodVarArgs('decompressData'.toJS, [ + var promise = html.window.callMethodVarArgs('decompressData'.toJS, [ data.toJS, - ]) as JSUint8Array?; + ]) as JSPromise; + var decompressedData = (await promise.toDart) as JSUint8Array?; if (decompressedData != null) { return decompressedData.toDart; } else { diff --git a/zstandard_web/pubspec.yaml b/zstandard_web/pubspec.yaml index c62f608..7402569 100644 --- a/zstandard_web/pubspec.yaml +++ b/zstandard_web/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard_web description: Web platform implementation of zstandard -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard/tree/master/zstandard_web +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard/tree/master/zstandard_web environment: sdk: ^3.6.0 @@ -22,7 +22,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - zstandard_platform_interface: ^1.3.32 + zstandard_platform_interface: ^1.4.0 web: ">=1.0.0 <2.0.0" dev_dependencies: diff --git a/zstandard_windows/CHANGELOG.md b/zstandard_windows/CHANGELOG.md index a60496b..224bf31 100644 --- a/zstandard_windows/CHANGELOG.md +++ b/zstandard_windows/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.4.0 - Zstd Update + +- Zstd lib updated +- Multiple symbol resolution bugs fixed +- Unified source of zstd (not one per platform) +- Web de/compression improved + ## 1.3.32 - Test Release - Test release diff --git a/zstandard_windows/README.md b/zstandard_windows/README.md index e0aedf2..eb96752 100644 --- a/zstandard_windows/README.md +++ b/zstandard_windows/README.md @@ -64,6 +64,6 @@ Unit tests run only on Windows (skipped on other platforms). For integration tes - **DLL not found**: Build your app with `flutter build windows` or run from the Flutter Windows runner so the native library is built and placed next to the executable. - **Wrong architecture**: Build for the correct target (x64 or arm64). -See the [documentation](https://github.com/landamessenger/zstandard/tree/master/docs) for more. +See the [documentation](https://github.com/vypdev/zstandard/tree/master/docs) for more. -

+

diff --git a/zstandard_windows/pubspec.yaml b/zstandard_windows/pubspec.yaml index 7fdb451..50ba884 100644 --- a/zstandard_windows/pubspec.yaml +++ b/zstandard_windows/pubspec.yaml @@ -1,9 +1,9 @@ name: zstandard_windows description: Windows platform implementation of zstandard -version: 1.3.32 +version: 1.4.0 -homepage: https://landamessenger.com -repository: https://github.com/landamessenger/zstandard/tree/master/zstandard_windows +homepage: https://vyp.dev +repository: https://github.com/vypdev/zstandard/tree/master/zstandard_windows environment: sdk: ^3.6.0 @@ -12,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - zstandard_platform_interface: ^1.3.32 + zstandard_platform_interface: ^1.4.0 ffi: ^2.1.3 dev_dependencies: