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
  /**
2
3
  * Runs the CPU-heavy parts of smoldot. Must be passed a port whose other end is passed to
3
4
  * `ClientOptions.portToWorker`.
@@ -23,6 +23,7 @@ exports.run = 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 instance = require("./internals/remote-instance.js");
27
28
  /**
28
29
  * Runs the CPU-heavy parts of smoldot. Must be passed a port whose other end is passed to
@@ -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.
@@ -20,9 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  // GNU General Public License for more details.
21
21
  // You should have received a copy of the GNU General Public License
22
22
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ /// <reference lib="dom" />
23
24
  import { default as wasmBase64 } from './internals/bytecode/wasm.js';
24
- import { classicDecode } from './internals/base64.js';
25
- import { inflate } from 'pako';
26
25
  /**
27
26
  * Compiles and returns the smoldot WebAssembly binary.
28
27
  */
@@ -32,7 +31,53 @@ export function compileBytecode() {
32
31
  // different file.
33
32
  // This is suboptimal compared to using `instantiateStreaming`, but it is the most
34
33
  // cross-platform cross-bundler approach.
35
- return WebAssembly.compile(inflate(classicDecode(wasmBase64)))
34
+ return WebAssembly.compile(yield zlibInflate(trustedBase64Decode(wasmBase64)))
36
35
  .then((m) => { return { wasm: m }; });
37
36
  });
38
37
  }
38
+ /**
39
+ * Applies the zlib inflate algorithm on the buffer.
40
+ */
41
+ function zlibInflate(buffer) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ // This code has been copy-pasted from the official streams draft specification.
44
+ // At the moment, it is found here: https://wicg.github.io/compression/#example-deflate-compress
45
+ const ds = new DecompressionStream('deflate');
46
+ const writer = ds.writable.getWriter();
47
+ writer.write(buffer);
48
+ writer.close();
49
+ const output = [];
50
+ const reader = ds.readable.getReader();
51
+ let totalSize = 0;
52
+ while (true) {
53
+ const { value, done } = yield reader.read();
54
+ if (done)
55
+ break;
56
+ output.push(value);
57
+ totalSize += value.byteLength;
58
+ }
59
+ const concatenated = new Uint8Array(totalSize);
60
+ let offset = 0;
61
+ for (const array of output) {
62
+ concatenated.set(array, offset);
63
+ offset += array.byteLength;
64
+ }
65
+ return concatenated;
66
+ });
67
+ }
68
+ /**
69
+ * Decodes a base64 string.
70
+ *
71
+ * The input is assumed to be correct.
72
+ */
73
+ function trustedBase64Decode(base64) {
74
+ // This code is a bit sketchy due to the fact that we decode into a string, but it seems to
75
+ // work.
76
+ const binaryString = atob(base64);
77
+ const size = binaryString.length;
78
+ const bytes = new Uint8Array(size);
79
+ for (let i = 0; i < size; i++) {
80
+ bytes[i] = binaryString.charCodeAt(i);
81
+ }
82
+ return bytes;
83
+ }
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  // GNU General Public License for more details.
21
21
  // You should have received a copy of the GNU General Public License
22
22
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ import { inflateSync } from 'node:zlib';
23
24
  import { default as wasmBase64 } from './internals/bytecode/wasm.js';
24
- import { inflate } from 'pako';
25
25
  /**
26
26
  * Compiles and returns the smoldot WebAssembly binary.
27
27
  */
@@ -31,7 +31,7 @@ export function compileBytecode() {
31
31
  // different file.
32
32
  // This is suboptimal compared to using `instantiateStreaming`, but it is the most
33
33
  // cross-platform cross-bundler approach.
34
- return WebAssembly.compile(inflate(Buffer.from(wasmBase64, 'base64')))
34
+ return WebAssembly.compile(inflateSync(Buffer.from(wasmBase64, 'base64')))
35
35
  .then((m) => { return { wasm: m }; });
36
36
  });
37
37
  }