capnweb 0.5.0 → 0.6.0

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.
package/dist/index.cjs CHANGED
@@ -26,6 +26,7 @@ var RpcTarget = workersModule ? workersModule.RpcTarget : class {
26
26
  };
27
27
  var AsyncFunction = (async function() {
28
28
  }).constructor;
29
+ var BUFFER_PROTOTYPE = typeof Buffer !== "undefined" ? Buffer.prototype : void 0;
29
30
  function typeForRpc(value) {
30
31
  switch (typeof value) {
31
32
  case "boolean":
@@ -57,6 +58,7 @@ function typeForRpc(value) {
57
58
  case Date.prototype:
58
59
  return "date";
59
60
  case Uint8Array.prototype:
61
+ case BUFFER_PROTOTYPE:
60
62
  return "bytes";
61
63
  case WritableStream.prototype:
62
64
  return "writable";
@@ -1386,12 +1388,19 @@ var Devaluator = class _Devaluator {
1386
1388
  let bytes = value;
1387
1389
  if (bytes.toBase64) {
1388
1390
  return ["bytes", bytes.toBase64({ omitPadding: true })];
1391
+ }
1392
+ let b64;
1393
+ if (typeof Buffer !== "undefined") {
1394
+ let buf = bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1395
+ b64 = buf.toString("base64");
1389
1396
  } else {
1390
- return [
1391
- "bytes",
1392
- btoa(String.fromCharCode.apply(null, bytes).replace(/=*$/, ""))
1393
- ];
1397
+ let binary = "";
1398
+ for (let i = 0; i < bytes.length; i++) {
1399
+ binary += String.fromCharCode(bytes[i]);
1400
+ }
1401
+ b64 = btoa(binary);
1394
1402
  }
1403
+ return ["bytes", b64.replace(/=+$/, "")];
1395
1404
  }
1396
1405
  case "headers":
1397
1406
  return ["headers", [...value]];
@@ -1607,10 +1616,11 @@ var Evaluator = class _Evaluator {
1607
1616
  }
1608
1617
  break;
1609
1618
  case "bytes": {
1610
- let b64 = Uint8Array;
1611
1619
  if (typeof value[1] == "string") {
1612
- if (b64.fromBase64) {
1613
- return b64.fromBase64(value[1]);
1620
+ if (typeof Buffer !== "undefined") {
1621
+ return Buffer.from(value[1], "base64");
1622
+ } else if (Uint8Array.fromBase64) {
1623
+ return Uint8Array.fromBase64(value[1]);
1614
1624
  } else {
1615
1625
  let bs = atob(value[1]);
1616
1626
  let len = bs.length;