Skip to content

Commit

Permalink
fix: support PromiseLike input to toFile (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored and chen-annie committed Jul 13, 2023
1 parent 6716dd2 commit f157769
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export type ToFileInput = Uploadable | Exclude<BlobPart, string> | AsyncIterable
* @returns a {@link File} with the given properties
*/
export async function toFile(
value: ToFileInput,
value: ToFileInput | PromiseLike<ToFileInput>,
name?: string | null | undefined,
options: FilePropertyBag | undefined = {},
): Promise<FileLike> {
Expand All @@ -121,8 +121,9 @@ export async function toFile(
return new File(bits, name, options);
}

async function getBytes(value: ToFileInput): Promise<Array<BlobPart>> {
if (value instanceof Promise) return getBytes(await (value as any));
async function getBytes(value: ToFileInput | PromiseLike<ToFileInput>): Promise<Array<BlobPart>> {
// resolve input promise or promiselike object
value = await value;

let parts: Array<BlobPart> = [];
if (
Expand Down

0 comments on commit f157769

Please sign in to comment.