readable.d.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { Readable } from 'stream'
  2. import { Blob } from 'buffer'
  3. export default BodyReadable
  4. declare class BodyReadable extends Readable {
  5. constructor (opts: {
  6. resume: (this: Readable, size: number) => void | null;
  7. abort: () => void | null;
  8. contentType?: string;
  9. contentLength?: number;
  10. highWaterMark?: number;
  11. })
  12. /** Consumes and returns the body as a string
  13. * https://fetch.spec.whatwg.org/#dom-body-text
  14. */
  15. text (): Promise<string>
  16. /** Consumes and returns the body as a JavaScript Object
  17. * https://fetch.spec.whatwg.org/#dom-body-json
  18. */
  19. json (): Promise<unknown>
  20. /** Consumes and returns the body as a Blob
  21. * https://fetch.spec.whatwg.org/#dom-body-blob
  22. */
  23. blob (): Promise<Blob>
  24. /** Consumes and returns the body as an Uint8Array
  25. * https://fetch.spec.whatwg.org/#dom-body-bytes
  26. */
  27. bytes (): Promise<Uint8Array>
  28. /** Consumes and returns the body as an ArrayBuffer
  29. * https://fetch.spec.whatwg.org/#dom-body-arraybuffer
  30. */
  31. arrayBuffer (): Promise<ArrayBuffer>
  32. /** Not implemented
  33. *
  34. * https://fetch.spec.whatwg.org/#dom-body-formdata
  35. */
  36. formData (): Promise<never>
  37. /** Returns true if the body is not null and the body has been consumed
  38. *
  39. * Otherwise, returns false
  40. *
  41. * https://fetch.spec.whatwg.org/#dom-body-bodyused
  42. */
  43. readonly bodyUsed: boolean
  44. /**
  45. * If body is null, it should return null as the body
  46. *
  47. * If body is not null, should return the body as a ReadableStream
  48. *
  49. * https://fetch.spec.whatwg.org/#dom-body-body
  50. */
  51. readonly body: never | undefined
  52. /** Dumps the response body by reading `limit` number of bytes.
  53. * @param opts.limit Number of bytes to read (optional) - Default: 131072
  54. * @param opts.signal AbortSignal to cancel the operation (optional)
  55. */
  56. dump (opts?: { limit: number; signal?: AbortSignal }): Promise<void>
  57. }