import { Blob } from './utils/blob-from.js'; import type { Writable } from 'node:stream'; import { Readable } from 'node:stream'; import { Buffer } from 'node:buffer'; import { FormData } from '@gjsify/formdata'; import { FetchBaseError } from './errors/base.js'; import type { Request } from './request.js'; import type { Response } from './response.js'; declare const INTERNALS: unique symbol; /** * Body mixin * * Ref: https://fetch.spec.whatwg.org/#body * * @param body Readable stream * @param opts Response options */ export default class Body { [INTERNALS]: { body: null | Buffer | Readable | Blob; stream: Readable | null; /** Memoized `body` wrapper — see the getter for why identity matters. */ webStream: ReadableStream | null; boundary: string; disturbed: boolean; error: null | FetchBaseError; }; size: number; constructor(body: BodyInit | Readable | Blob | Buffer | null, options?: { size?: number; headers?: unknown; }); /** * The body as a `ReadableStream`. * * Per the Fetch spec `body` is an ATTRIBUTE holding one stream, so every * read must return the SAME object — `res.body === res.body`. This used to * build a fresh wrapper per access, each one subscribing to the same * already-flowing `Readable`: the first reader got every byte and every * later one got an immediate `done`, with no error anywhere. * * That is not a theoretical spec detail. Consumers legitimately touch * `.body` several times in a row — three.js' `FileLoader` guards with * `response.body === undefined`, then `response.body.getReader === undefined`, * and only then calls `response.body.getReader()`, so it read the THIRD, * empty stream. Downstream: an empty response text, an LDraw model that * parsed to zero meshes, and a viewer showing nothing but its clear colour. */ get body(): ReadableStream | null; get _stream(): Readable; /** Return the raw body buffer without consuming the stream (used by Request._send). */ get _rawBodyBuffer(): Buffer | null; get bodyUsed(): boolean; /** * Decode response as ArrayBuffer */ arrayBuffer(): Promise; formData(): Promise; /** * Return raw response as Blob */ blob(): Promise; /** * Decode response as json */ json(): Promise; /** * Decode response as text */ text(): Promise; } /** * Clone body given Res/Req instance */ export declare const clone: (instance: T, highWaterMark?: number) => Blob | Readable | Buffer; /** * Extract a Content-Type value from a body. */ export declare const extractContentType: (body: BodyInit | Readable | Blob | Buffer | null, request: Request | Response) => string | null; /** * Get total bytes of a body. */ export declare const getTotalBytes: (request: Request) => number | null; /** * Write a Body to a Node.js WritableStream. */ export declare const writeToStream: (dest: Writable, { body }: { body: Readable | null; }) => Promise; export {};