readable.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 ArrayBuffer
  23. * https://fetch.spec.whatwg.org/#dom-body-arraybuffer
  24. */
  25. arrayBuffer(): Promise<ArrayBuffer>
  26. /** Not implemented
  27. *
  28. * https://fetch.spec.whatwg.org/#dom-body-formdata
  29. */
  30. formData(): Promise<never>
  31. /** Returns true if the body is not null and the body has been consumed
  32. *
  33. * Otherwise, returns false
  34. *
  35. * https://fetch.spec.whatwg.org/#dom-body-bodyused
  36. */
  37. readonly bodyUsed: boolean
  38. /**
  39. * If body is null, it should return null as the body
  40. *
  41. * If body is not null, should return the body as a ReadableStream
  42. *
  43. * https://fetch.spec.whatwg.org/#dom-body-body
  44. */
  45. readonly body: never | undefined
  46. /** Dumps the response body by reading `limit` number of bytes.
  47. * @param opts.limit Number of bytes to read (optional) - Default: 262144
  48. */
  49. dump(opts?: { limit: number }): Promise<void>
  50. }