<div align="center">
<h1>wasm-zstd</h1>
<p>
<strong>Big data transmission solution based on Webassembly</strong>
<br /><br />
<strong>基于Webassembly的大数据传输解决方案</strong>
</p>
<p>
<sub>Made with ❤︎ by
<a href="https://github.com/JousenZhou">JousenZhou</a>
</sub>
</p>
<p>
<a href="https://github.com/JousenZhou/wasm-zstd"><img src="https://img.shields.io/badge/Github Page-JousenZhou-yellow" /></a>
<a href="https://github.com/JousenZhou"><img src="https://img.shields.io/badge/Author-Jousen-blueviolet" /></a>
</div>
### Usage
开发,构建和运行。ps: ( !!!) 需要启动go服务
```bash
# 获取远程仓库代码
git clone https://github.com/JousenZhou/wasm-zstd
# 进入目录
cd wasm-zstd
# 解压go服务端[命令不行手动解压吧]
unrar e ./GoServer/GoServer.rar ./GoServer
# 打开执行Go服务.exe
./GoServer/GoServer.exe
# 安装依赖
yarn
# 启动项目
yarn devstart
# 在浏览器访问 http://localhost:3000
```
### 基本思路与探讨
服务端发送数据前用zstd将数据进行一次压缩,代替服务端可配置的gzip压缩。zstd是近几年谷歌新推出的压缩算法拥有不错的压缩率|压缩时间,相较于gzip有约近5~10倍提升。由于压缩后得到是Uint8Array数组结果集,所以前端需要对这份数据进行解压。前端如果在javeScrtpt层进行解压效率会很低,因为javeScript运行会转成c++再编译,在这转换过程性能会大量损耗。因此Webassembly技术将可解决这个难题。
<img src="./static/1.jpg" alt="5494980-14542950db892d9f" width="500px" />
### 多线程挂载wasm模块 + 数据解压
```js
// zstd-wasm base64编码
let wasm = 'xxx'
let heap,instance;
const IMPORT_OBJECT = {
env: {
emscripten_notify_memory_growth: function() {
heap = new Uint8Array(instance.exports.memory.buffer);
}
}
};
function loadWebAssembly(path, imports = {}) {
return fetch(path)
.then((response) => response.arrayBuffer())
.then((arrayBuffer) => WebAssembly.instantiate(arrayBuffer, IMPORT_OBJECT))
.then((result => {
instance = result.instance;
IMPORT_OBJECT.env.emscripten_notify_memory_growth(0);
}))
}
loadWebAssembly('data:application/wasm;base64,' + wasm).then();
onmessage = function(evt){
let array = new Uint8Array(evt.data);
const compressedSize = array.byteLength;
const compressedPtr = instance.exports.malloc(compressedSize);
let heap = new Uint8Array(instance.exports.memory.buffer);
heap.set(array, compressedPtr);
let uncompressedSize = Number(instance.exports.ZSTD_findDecompressedSize(compressedPtr, compressedSize));
const uncompressedPtr = instance.exports.malloc(uncompressedSize);
const actualSize = instance.exports.ZSTD_decompress(uncompressedPtr, uncompressedSize, compressedPtr, compressedSize);
const dec = heap.slice(uncompressedPtr, uncompressedPtr + actualSize);
instance.exports.free(compressedPtr);
instance.exports.free(uncompressedPtr);
postMessage(JSON.parse(new TextDecoder().decode(dec)))
};
```
### 服务端压缩数据简易代码
Java:
<p><img src="./static/5.jpg" alt="5494980-14542950db892d9f" style="zoom:50%;" /></p>
Go:
<p><img src="./static/4.png" alt="5494980-14542950db892d9f" style="zoom:50%;" /></p>
### 测试结果
ps:不要在本地测试没意义;
外网测试:
<div>
<img src="./static/3.png" alt="5494980-14542950db892d9f" style="zoom:50%;" />
<img src="./static/2.png" alt="5494980-14542950db892d9f" style="zoom:50%;" />
</div>
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】: 包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。 包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。 【项目质量】: 所有源码都经过严格测试,可以直接运行。 功能在确认正常工作后才上传。 【适用人群】: 适用于希望学习不同技术领域的小白或进阶学习者。 可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 【附加价值】: 项目具有较高的学习借鉴价值,也可直接拿来修改复刻。 对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。 【沟通交流】: 有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
基于webassembly 大数据传输优化方案探讨研究。.zip (26个子文件)
资料总结
yarn.lock 98KB
GoServer
GoServer.rar 6.98MB
app.js 1KB
.idea
wasm-zstd2.iml 288B
vcs.xml 185B
misc.xml 179B
modules.xml 279B
.gitignore 39B
package.json 488B
bin
www 2KB
public
stylesheets
style.css 149B
style.sass 100B
style.css.map 216B
zstddec.wasm 46KB
javascripts
worker.js 40KB
zstd.js 464B
routes
index.js 1KB
.gitignore 39B
static
3.png 9KB
1.jpg 39KB
5.jpg 913KB
4.png 19KB
2.png 21KB
README.md 4KB
views
index.ejs 1KB
error.ejs 83B
共 26 条
- 1
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功