readable.d.ts 1.7 KB

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