smoldot 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ /// <reference lib="dom" />
1
2
  import { SmoldotBytecode } from './public-types.js';
2
3
  /**
3
4
  * Compiles and returns the smoldot WebAssembly binary.
@@ -23,9 +23,8 @@ exports.compileBytecode = void 0;
23
23
  // GNU General Public License for more details.
24
24
  // You should have received a copy of the GNU General Public License
25
25
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
26
+ /// <reference lib="dom" />
26
27
  const wasm_js_1 = require("./internals/bytecode/wasm.js");
27
- const base64_js_1 = require("./internals/base64.js");
28
- const pako_1 = require("pako");
29
28
  /**
30
29
  * Compiles and returns the smoldot WebAssembly binary.
31
30
  */
@@ -35,8 +34,54 @@ function compileBytecode() {
35
34
  // different file.
36
35
  // This is suboptimal compared to using `instantiateStreaming`, but it is the most
37
36
  // cross-platform cross-bundler approach.
38
- return WebAssembly.compile((0, pako_1.inflate)((0, base64_js_1.classicDecode)(wasm_js_1.default)))
37
+ return WebAssembly.compile(yield zlibInflate(trustedBase64Decode(wasm_js_1.default)))
39
38
  .then((m) => { return { wasm: m }; });
40
39
  });
41
40
  }
42
41
  exports.compileBytecode = compileBytecode;
42
+ /**
43
+ * Applies the zlib inflate algorithm on the buffer.
44
+ */
45
+ function zlibInflate(buffer) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ // This code has been copy-pasted from the official streams draft specification.
48
+ // At the moment, it is found here: https://wicg.github.io/compression/#example-deflate-compress
49
+ const ds = new DecompressionStream('deflate');
50
+ const writer = ds.writable.getWriter();
51
+ writer.write(buffer);
52
+ writer.close();
53
+ const output = [];
54
+ const reader = ds.readable.getReader();
55
+ let totalSize = 0;
56
+ while (true) {
57
+ const { value, done } = yield reader.read();
58
+ if (done)
59
+ break;
60
+ output.push(value);
61
+ totalSize += value.byteLength;
62
+ }
63
+ const concatenated = new Uint8Array(totalSize);
64
+ let offset = 0;
65
+ for (const array of output) {
66
+ concatenated.set(array, offset);
67
+ offset += array.byteLength;
68
+ }
69
+ return concatenated;
70
+ });
71
+ }
72
+ /**
73
+ * Decodes a base64 string.
74
+ *
75
+ * The input is assumed to be correct.
76
+ */
77
+ function trustedBase64Decode(base64) {
78
+ // This code is a bit sketchy due to the fact that we decode into a string, but it seems to
79
+ // work.
80
+ const binaryString = atob(base64);
81
+ const size = binaryString.length;
82
+ const bytes = new Uint8Array(size);
83
+ for (let i = 0; i < size; i++) {
84
+ bytes[i] = binaryString.charCodeAt(i);
85
+ }
86
+ return bytes;
87
+ }
@@ -23,8 +23,8 @@ exports.compileBytecode = void 0;
23
23
  // GNU General Public License for more details.
24
24
  // You should have received a copy of the GNU General Public License
25
25
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
26
+ const node_zlib_1 = require("node:zlib");
26
27
  const wasm_js_1 = require("./internals/bytecode/wasm.js");
27
- const pako_1 = require("pako");
28
28
  /**
29
29
  * Compiles and returns the smoldot WebAssembly binary.
30
30
  */
@@ -34,7 +34,7 @@ function compileBytecode() {
34
34
  // different file.
35
35
  // This is suboptimal compared to using `instantiateStreaming`, but it is the most
36
36
  // cross-platform cross-bundler approach.
37
- return WebAssembly.compile((0, pako_1.inflate)(Buffer.from(wasm_js_1.default, 'base64')))
37
+ return WebAssembly.compile((0, node_zlib_1.inflateSync)(Buffer.from(wasm_js_1.default, 'base64')))
38
38
  .then((m) => { return { wasm: m }; });
39
39
  });
40
40
  }