0.2.1 • Published 10 months ago

ungzip-wasm v0.2.1

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

编译wasm ungzip压缩字符串

更新代码后打包命令:

wasm-pack build --target bundler --release

输出的目录在 pkg目录下,默认是一个npm的包。

发布使用方式

npm install ungzip-wasm

vue引入代码

  1. 引入 wasm-loader
npm install wasm-loader -D
  1. vue.config.js 加入配置
module.exports = {
    configureWebpack: {
        module: {
            rules: [
                {
                    test: /\.wasm$/,
                    type: 'webassembly/experimental',
                },
                {
                    test: /\.(png|jpg|gif|svg|ico)$/,
                    use: [
                        {
                            loader: 'file-loader',
                            options: {
                                name: '[name].[ext]',
                                outputPath: 'assets/',
                            },
                        },
                    ],
                },
            ],
        },
    },
};
  1. 在需要用到的地方引入。由于wasm是二进制文件,因此需要异步引入
async function init() {
  // 异步导入 WebAssembly 模块
  const wasmModule = await import('ungzip-wasm');

  // 使用 WebAssembly 模块
  try {
    const result = wasmModule.decompress_string('your_base64_string');
  } catch (e) {
    // wasm内部对错误并没有进行处理,在这里处理下
  }
  console.log('Decompressed string:', result);
}

init().catch(console.error);
0.2.1

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago