From c351988d5b1eec31d0ac837c48d7908aca45c160 Mon Sep 17 00:00:00 2001 From: Petra Jaros Date: Fri, 30 Aug 2024 15:04:46 -0400 Subject: [PATCH] refactor: `BlobLike`'s `stream()` matches `Blob`'s (#1535) Should return a `ReadableStream`, not a `ReadableStream`. Get it straight from `Blob` to be sure it matches. This bit me while trying to work with the API. --- packages/upload-client/src/car.js | 12 +++++++++--- packages/upload-client/src/types.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/upload-client/src/car.js b/packages/upload-client/src/car.js index 73e50ddb5..67bc3b06a 100644 --- a/packages/upload-client/src/car.js +++ b/packages/upload-client/src/car.js @@ -98,11 +98,16 @@ export class BlockStream extends ReadableStream { } } -/* c8 ignore next 20 */ +/* c8 ignore start */ /** + * {@link ReadableStream} is an async iterable in newer environments, but it's + * not standard yet. This function normalizes a {@link ReadableStream} to a + * definite async iterable. + * * @template T - * @param {{ getReader: () => ReadableStreamDefaultReader } | AsyncIterable} stream - * @returns {AsyncIterable} + * @param {ReadableStream | AsyncIterable} stream + * @returns {AsyncIterable} An async iterable of the contents of the + * {@link stream} (possibly {@link stream} itself). */ function toIterable(stream) { return Symbol.asyncIterator in stream @@ -120,3 +125,4 @@ function toIterable(stream) { } })() } +/* c8 ignore end */ diff --git a/packages/upload-client/src/types.ts b/packages/upload-client/src/types.ts index 7d49586e3..38a41f2f0 100644 --- a/packages/upload-client/src/types.ts +++ b/packages/upload-client/src/types.ts @@ -406,7 +406,7 @@ export interface BlobLike { /** * Returns a ReadableStream which yields the Blob data. */ - stream: () => ReadableStream + stream: Blob['stream'] } export interface FileLike extends BlobLike {