capnweb 0.5.0 → 0.6.1

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.
@@ -49,6 +49,7 @@ var RpcTarget = workersModule ? workersModule.RpcTarget : class {
49
49
  };
50
50
  var AsyncFunction = (async function() {
51
51
  }).constructor;
52
+ var BUFFER_PROTOTYPE = typeof Buffer !== "undefined" ? Buffer.prototype : void 0;
52
53
  function typeForRpc(value) {
53
54
  switch (typeof value) {
54
55
  case "boolean":
@@ -80,6 +81,7 @@ function typeForRpc(value) {
80
81
  case Date.prototype:
81
82
  return "date";
82
83
  case Uint8Array.prototype:
84
+ case BUFFER_PROTOTYPE:
83
85
  return "bytes";
84
86
  case WritableStream.prototype:
85
87
  return "writable";
@@ -1409,12 +1411,19 @@ var Devaluator = class _Devaluator {
1409
1411
  let bytes = value;
1410
1412
  if (bytes.toBase64) {
1411
1413
  return ["bytes", bytes.toBase64({ omitPadding: true })];
1414
+ }
1415
+ let b64;
1416
+ if (typeof Buffer !== "undefined") {
1417
+ let buf = bytes instanceof Buffer ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
1418
+ b64 = buf.toString("base64");
1412
1419
  } else {
1413
- return [
1414
- "bytes",
1415
- btoa(String.fromCharCode.apply(null, bytes).replace(/=*$/, ""))
1416
- ];
1420
+ let binary = "";
1421
+ for (let i = 0; i < bytes.length; i++) {
1422
+ binary += String.fromCharCode(bytes[i]);
1423
+ }
1424
+ b64 = btoa(binary);
1417
1425
  }
1426
+ return ["bytes", b64.replace(/=+$/, "")];
1418
1427
  }
1419
1428
  case "headers":
1420
1429
  return ["headers", [...value]];
@@ -1630,10 +1639,11 @@ var Evaluator = class _Evaluator {
1630
1639
  }
1631
1640
  break;
1632
1641
  case "bytes": {
1633
- let b64 = Uint8Array;
1634
1642
  if (typeof value[1] == "string") {
1635
- if (b64.fromBase64) {
1636
- return b64.fromBase64(value[1]);
1643
+ if (typeof Buffer !== "undefined") {
1644
+ return Buffer.from(value[1], "base64");
1645
+ } else if (Uint8Array.fromBase64) {
1646
+ return Uint8Array.fromBase64(value[1]);
1637
1647
  } else {
1638
1648
  let bs = atob(value[1]);
1639
1649
  let len = bs.length;