@php-wasm/universal 2.0.9 → 2.0.11

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/index.js CHANGED
@@ -524,7 +524,7 @@ const responseTexts = {
524
524
  };
525
525
  class StreamedPHPResponse {
526
526
  constructor(e, r, s, n) {
527
- this.parsedHeaders = null, this.cachedStdoutText = null, this.cachedStderrText = null, this.headersStream = e, this.stdout = r, this.stderr = s, this.exitCode = n;
527
+ this.parsedHeaders = null, this.cachedStdoutBytes = null, this.cachedStderrText = null, this.headersStream = e, this.stdout = r, this.stderr = s, this.exitCode = n;
528
528
  }
529
529
  /**
530
530
  * True if the response is successful (HTTP status code 200-399),
@@ -567,7 +567,15 @@ class StreamedPHPResponse {
567
567
  * Exposes the stdout bytes as they're produced by the PHP instance
568
568
  */
569
569
  get stdoutText() {
570
- return this.cachedStdoutText || (this.cachedStdoutText = streamToText(this.stdout)), this.cachedStdoutText;
570
+ return this.stdoutBytes.then(
571
+ (e) => new TextDecoder().decode(e)
572
+ );
573
+ }
574
+ /**
575
+ * Exposes the stdout bytes as they're produced by the PHP instance
576
+ */
577
+ get stdoutBytes() {
578
+ return this.cachedStdoutBytes || (this.cachedStdoutBytes = streamToBytes(this.stdout)), this.cachedStdoutBytes;
571
579
  }
572
580
  /**
573
581
  * Exposes the stderr bytes as they're produced by the PHP instance
@@ -608,6 +616,23 @@ async function streamToText(t) {
608
616
  n && r.push(n);
609
617
  }
610
618
  }
619
+ async function streamToBytes(t) {
620
+ const e = t.getReader(), r = [];
621
+ for (; ; ) {
622
+ const { done: s, value: n } = await e.read();
623
+ if (s) {
624
+ const i = r.reduce(
625
+ (c, l) => c + l.byteLength,
626
+ 0
627
+ ), o = new Uint8Array(i);
628
+ let a = 0;
629
+ for (const c of r)
630
+ o.set(c, a), a += c.byteLength;
631
+ return o;
632
+ }
633
+ n && r.push(n);
634
+ }
635
+ }
611
636
  class PHPResponse {
612
637
  constructor(e, r, s, n = "", i = 0) {
613
638
  this.httpStatusCode = e, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
@@ -634,7 +659,7 @@ class PHPResponse {
634
659
  return await e.finished, new PHPResponse(
635
660
  await e.httpStatusCode,
636
661
  await e.headers,
637
- new TextEncoder().encode(await e.stdoutText),
662
+ await e.stdoutBytes,
638
663
  await e.stderrText,
639
664
  await e.exitCode
640
665
  );
@@ -874,7 +899,7 @@ class PHPExecutionFailureError extends Error {
874
899
  }
875
900
  }
876
901
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
877
- var k, E, x, g, v, T, h, z, W, $, B, V, G, J, Y, K, L, X, O, U;
902
+ var k, E, x, g, v, T, h, z, B, W, $, V, G, J, Y, K, L, X, O, U;
878
903
  class PHP {
879
904
  /**
880
905
  * Initializes a PHP runtime.
@@ -1294,13 +1319,13 @@ class PHP {
1294
1319
  const e = await this.semaphore.acquire();
1295
1320
  let r;
1296
1321
  const s = m(this, h, U).call(this, async () => {
1297
- if (u(this, E) || (await m(this, h, W).call(this), f(this, E, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1322
+ if (u(this, E) || (await m(this, h, B).call(this), f(this, E, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1298
1323
  throw new Error(
1299
1324
  `The script path "${t.scriptPath}" does not exist.`
1300
1325
  );
1301
- m(this, h, $).call(this, t.relativeUri || ""), m(this, h, J).call(this, t.method || "GET");
1326
+ m(this, h, W).call(this, t.relativeUri || ""), m(this, h, J).call(this, t.method || "GET");
1302
1327
  const i = normalizeHeaders(t.headers || {}), o = i.host || "example.com:443", a = m(this, h, G).call(this, o, t.protocol || "http");
1303
- if (m(this, h, B).call(this, o), m(this, h, V).call(this, a), m(this, h, Y).call(this, i), t.body && (r = m(this, h, K).call(this, t.body)), typeof t.code == "string")
1328
+ if (m(this, h, $).call(this, o), m(this, h, V).call(this, a), m(this, h, Y).call(this, i), t.body && (r = m(this, h, K).call(this, t.body)), typeof t.code == "string")
1304
1329
  this.writeFile("/internal/eval.php", t.code), m(this, h, L).call(this, "/internal/eval.php");
1305
1330
  else if (typeof t.scriptPath == "string")
1306
1331
  m(this, h, L).call(this, t.scriptPath || "");
@@ -1632,11 +1657,11 @@ z = function(t, e, r) {
1632
1657
  ["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = e[n];
1633
1658
  }
1634
1659
  return s;
1635
- }, W = function() {
1660
+ }, B = function() {
1636
1661
  return this[__private__dont__use].ccall("php_wasm_init", null, [], [], {
1637
1662
  isAsync: !0
1638
1663
  });
1639
- }, $ = function(t) {
1664
+ }, W = function(t) {
1640
1665
  this[__private__dont__use].ccall(
1641
1666
  "wasm_set_request_uri",
1642
1667
  null,
@@ -1650,7 +1675,7 @@ z = function(t, e, r) {
1650
1675
  [STRING],
1651
1676
  [e]
1652
1677
  );
1653
- }, B = function(t) {
1678
+ }, $ = function(t) {
1654
1679
  this[__private__dont__use].ccall(
1655
1680
  "wasm_set_request_host",
1656
1681
  null,