Skip to content

Commit

Permalink
refactor: BlobLike's stream() matches Blob's (#1535)
Browse files Browse the repository at this point in the history
Should return a `ReadableStream<Uint8Array>`, not a
`ReadableStream<any>`. Get it straight from `Blob` to be sure it
matches.

This bit me while trying to work with the API.
  • Loading branch information
Peeja authored Aug 30, 2024
1 parent fb2fd66 commit c351988
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions packages/upload-client/src/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> } | AsyncIterable<T>} stream
* @returns {AsyncIterable<T>}
* @param {ReadableStream<T> | AsyncIterable<T>} stream
* @returns {AsyncIterable<T>} An async iterable of the contents of the
* {@link stream} (possibly {@link stream} itself).
*/
function toIterable(stream) {
return Symbol.asyncIterator in stream
Expand All @@ -120,3 +125,4 @@ function toIterable(stream) {
}
})()
}
/* c8 ignore end */
2 changes: 1 addition & 1 deletion packages/upload-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c351988

Please sign in to comment.