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