From 66c64d0c58f6b855c1456d5913df76bc8fa6f3be Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 23 Apr 2024 13:07:27 +0530 Subject: [PATCH] Let the caller decide --- .../photos/src/services/upload/uploadService.ts | 8 +++----- web/apps/photos/src/utils/native-stream.ts | 14 +++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/web/apps/photos/src/services/upload/uploadService.ts b/web/apps/photos/src/services/upload/uploadService.ts index f3e8b852e..6bfbcb103 100644 --- a/web/apps/photos/src/services/upload/uploadService.ts +++ b/web/apps/photos/src/services/upload/uploadService.ts @@ -438,14 +438,12 @@ const readFileOrPath = async ( } } else { const path = fileOrPath; - const { stream, size } = await readStream(path); + const { response, size } = await readStream(path); if (size > MULTIPART_PART_SIZE) { const chunkCount = Math.ceil(size / FILE_READER_CHUNK_SIZE); - dataOrStream = { stream, chunkCount }; + dataOrStream = { stream: response.body, chunkCount }; } else { - dataOrStream = new Uint8Array( - await new Response(stream).arrayBuffer(), - ); + dataOrStream = new Uint8Array(await response.arrayBuffer()); } } diff --git a/web/apps/photos/src/utils/native-stream.ts b/web/apps/photos/src/utils/native-stream.ts index aef06845c..52da84f99 100644 --- a/web/apps/photos/src/utils/native-stream.ts +++ b/web/apps/photos/src/utils/native-stream.ts @@ -14,13 +14,17 @@ * @param path The path on the file on the user's local filesystem whose * contents we want to stream. * - * @return A (ReadableStream, size) tuple. The {@link ReadableStream} can be - * used to read the files contents in a streaming manner. The size value is the - * the size of the file that we'll be reading from disk. + * @return A ({@link Response}, size) tuple. + * + * * The response contains the contents of the file. In particular, the `body` + * {@link ReadableStream} property of this response can be used to read the + * files contents in a streaming manner. + * + * * The size is the size of the file that we'll be reading from disk. */ export const readStream = async ( path: string, -): Promise<{ stream: ReadableStream; size: number }> => { +): Promise<{ response: Response; size: number }> => { const req = new Request(`stream://read${path}`, { method: "GET", }); @@ -37,7 +41,7 @@ export const readStream = async ( `Got a numeric Content-Length when reading a stream. The response was ${res}`, ); - return { stream: res.body, size }; + return { response: res, size }; }; /**