to-file.d.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import type { FilePropertyBag } from "./builtin-types.js";
  2. type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
  3. /**
  4. * Intended to match DOM Blob, node-fetch Blob, node:buffer Blob, etc.
  5. * Don't add arrayBuffer here, node-fetch doesn't have it
  6. */
  7. interface BlobLike {
  8. /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/size) */
  9. readonly size: number;
  10. /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/type) */
  11. readonly type: string;
  12. /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
  13. text(): Promise<string>;
  14. /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
  15. slice(start?: number, end?: number): BlobLike;
  16. }
  17. /**
  18. * Intended to match DOM File, node:buffer File, undici File, etc.
  19. */
  20. interface FileLike extends BlobLike {
  21. /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/lastModified) */
  22. readonly lastModified: number;
  23. /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/File/name) */
  24. readonly name?: string | undefined;
  25. }
  26. /**
  27. * Intended to match DOM Response, node-fetch Response, undici Response, etc.
  28. */
  29. export interface ResponseLike {
  30. url: string;
  31. blob(): Promise<BlobLike>;
  32. }
  33. export type ToFileInput = FileLike | ResponseLike | Exclude<BlobLikePart, string> | AsyncIterable<BlobLikePart>;
  34. /**
  35. * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
  36. * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
  37. * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
  38. * @param {Object=} options additional properties
  39. * @param {string=} options.type the MIME type of the content
  40. * @param {number=} options.lastModified the last modified timestamp
  41. * @returns a {@link File} with the given properties
  42. */
  43. export declare function toFile(value: ToFileInput | PromiseLike<ToFileInput>, name?: string | null | undefined, options?: FilePropertyBag | undefined): Promise<File>;
  44. export {};
  45. //# sourceMappingURL=to-file.d.ts.map