aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEl RIDO <[email protected]>2021-06-20 08:43:44 +0200
committerEl RIDO <[email protected]>2021-06-20 08:43:44 +0200
commita4a32f6b9e0213797ad43b9b458dbd5fbc86614b (patch)
tree59dca1f056f223f681c6f0f1a6a324e11b967967
parent5f2daa5cd6e609bd88ef95e0c2b3ab27a6c75298 (diff)
downloadprivatebin-a4a32f6b9e0213797ad43b9b458dbd5fbc86614b.tar.gz
privatebin-a4a32f6b9e0213797ad43b9b458dbd5fbc86614b.tar.bz2
privatebin-a4a32f6b9e0213797ad43b9b458dbd5fbc86614b.zip
switch to streaming WASM loading, fixes #814
-rw-r--r--js/zlib-1.2.11.js57
-rw-r--r--tpl/bootstrap.php2
-rw-r--r--tpl/page.php2
3 files changed, 26 insertions, 35 deletions
diff --git a/js/zlib-1.2.11.js b/js/zlib-1.2.11.js
index ed0abea8..835cb968 100644
--- a/js/zlib-1.2.11.js
+++ b/js/zlib-1.2.11.js
@@ -1,6 +1,6 @@
'use strict';
-(function() {
+(function () {
let ret;
async function initialize() {
@@ -23,16 +23,7 @@
_abort: errno => { console.error(`Error: ${errno}`) },
_grow: () => { },
};
-
- let buff;
- if (typeof fetch === 'undefined') {
- buff = fs.readFileSync('zlib-1.2.11.wasm');
- } else {
- const resp = await fetch('js/zlib-1.2.11.wasm');
- buff = await resp.arrayBuffer();
- }
- const module = await WebAssembly.compile(buff);
- const ins = await WebAssembly.instantiate(module, { env });
+ const ins = await WebAssembly.instantiateStreaming(fetch('js/zlib-1.2.11.wasm'), { env });
const srcPtr = ins.exports._malloc(CHUNK_SIZE);
const dstPtr = ins.exports._malloc(CHUNK_SIZE);
@@ -116,28 +107,28 @@
}
ret = {
- inflate(rawDeflateBuffer) {
- const rawInf = new RawInf();
- for (let offset = 0; offset < rawDeflateBuffer.length; offset += CHUNK_SIZE) {
- const end = Math.min(offset + CHUNK_SIZE, rawDeflateBuffer.length);
- const chunk = rawDeflateBuffer.subarray(offset, end);
- rawInf.inflate(chunk);
- }
- const ret = rawInf.getBuffer();
- rawInf.destroy();
- return ret;
- },
- deflate(rawInflateBuffer) {
- const rawDef = new RawDef();
- for (let offset = 0; offset < rawInflateBuffer.length; offset += CHUNK_SIZE) {
- const end = Math.min(offset + CHUNK_SIZE, rawInflateBuffer.length);
- const chunk = rawInflateBuffer.subarray(offset, end);
- rawDef.deflate(chunk, rawInflateBuffer.length <= offset + CHUNK_SIZE);
- }
- const ret = rawDef.getBuffer();
- rawDef.destroy();
- return ret;
- },
+ inflate(rawDeflateBuffer) {
+ const rawInf = new RawInf();
+ for (let offset = 0; offset < rawDeflateBuffer.length; offset += CHUNK_SIZE) {
+ const end = Math.min(offset + CHUNK_SIZE, rawDeflateBuffer.length);
+ const chunk = rawDeflateBuffer.subarray(offset, end);
+ rawInf.inflate(chunk);
+ }
+ const ret = rawInf.getBuffer();
+ rawInf.destroy();
+ return ret;
+ },
+ deflate(rawInflateBuffer) {
+ const rawDef = new RawDef();
+ for (let offset = 0; offset < rawInflateBuffer.length; offset += CHUNK_SIZE) {
+ const end = Math.min(offset + CHUNK_SIZE, rawInflateBuffer.length);
+ const chunk = rawInflateBuffer.subarray(offset, end);
+ rawDef.deflate(chunk, rawInflateBuffer.length <= offset + CHUNK_SIZE);
+ }
+ const ret = rawDef.getBuffer();
+ rawDef.destroy();
+ return ret;
+ },
}
return ret;
diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php
index 1e4eae00..86c15de2 100644
--- a/tpl/bootstrap.php
+++ b/tpl/bootstrap.php
@@ -54,7 +54,7 @@ if ($ZEROBINCOMPATIBILITY) :
<?php
endif;
?>
- <script type="text/javascript" data-cfasync="false" src="js/zlib-1.2.11.js" integrity="sha512-Yey/0yoaVmSbqMEyyff3DIu8kCPwpHvHf7tY1AuZ1lrX9NPCMg87PwzngMi+VNbe4ilCApmePeuKT869RTcyCQ==" crossorigin="anonymous"></script>
+ <script type="text/javascript" data-cfasync="false" src="js/zlib-1.2.11.js" integrity="sha512-Ji/WNgLpfd+sJgYjJv67Tjs4aYeMVrMeYIgCp5VU+EB8INzpfilh0ptjBHa3xem8tLCMROgJR10ilK3saci2YA==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/base-x-3.0.7.js" integrity="sha512-/Bi1AJIP0TtxEB+Jh6Hk809H1G7vn4iJV80qagslf0+Hm0UjUi1s3qNrn1kZULjzUYuaf6ck0ndLGJ7MxWLmgQ==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/rawinflate-0.3.js" integrity="sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/bootstrap-3.3.7.js" integrity="sha512-iztkobsvnjKfAtTNdHkGVjAYTrrtlC7mGp/54c40wowO7LhURYl3gVzzcEqGl/qKXQltJ2HwMrdLcNUdo+N/RQ==" crossorigin="anonymous"></script>
diff --git a/tpl/page.php b/tpl/page.php
index 28f37b90..f3b26d4e 100644
--- a/tpl/page.php
+++ b/tpl/page.php
@@ -33,7 +33,7 @@ if ($ZEROBINCOMPATIBILITY):
<?php
endif;
?>
- <script type="text/javascript" data-cfasync="false" src="js/zlib-1.2.11.js" integrity="sha512-Yey/0yoaVmSbqMEyyff3DIu8kCPwpHvHf7tY1AuZ1lrX9NPCMg87PwzngMi+VNbe4ilCApmePeuKT869RTcyCQ==" crossorigin="anonymous"></script>
+ <script type="text/javascript" data-cfasync="false" src="js/zlib-1.2.11.js" integrity="sha512-Ji/WNgLpfd+sJgYjJv67Tjs4aYeMVrMeYIgCp5VU+EB8INzpfilh0ptjBHa3xem8tLCMROgJR10ilK3saci2YA==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/base-x-3.0.7.js" integrity="sha512-/Bi1AJIP0TtxEB+Jh6Hk809H1G7vn4iJV80qagslf0+Hm0UjUi1s3qNrn1kZULjzUYuaf6ck0ndLGJ7MxWLmgQ==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/rawinflate-0.3.js" integrity="sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==" crossorigin="anonymous"></script>
<?php