"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var response_reader_exports = {};
__export(response_reader_exports, {
  readIncomingResponse: () => readIncomingResponse
});
module.exports = __toCommonJS(response_reader_exports);
var import_buffer = require("../primordials/buffer");
var import_json = require("../primordials/json");
async function readIncomingResponse(msg) {
  const chunks = [];
  for await (const chunk of msg) {
    chunks.push(chunk);
  }
  const body = (0, import_buffer.BufferConcat)(chunks);
  const status = msg.statusCode ?? 0;
  const statusText = msg.statusMessage ?? "";
  return {
    arrayBuffer: () => body.buffer.slice(
      body.byteOffset,
      body.byteOffset + body.byteLength
    ),
    body,
    headers: msg.headers,
    json: () => (0, import_json.JSONParse)(body.toString("utf8")),
    ok: status >= 200 && status < 300,
    rawResponse: msg,
    status,
    statusText,
    text: () => body.toString("utf8")
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  readIncomingResponse
});
