Skip to content

Commit

Permalink
fix(upload): should a single chunk if the stream is equal to partsize
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyicun authored and kuhe committed Apr 10, 2024
1 parent 50002cf commit a71cbd1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/lib-storage/src/chunks/getChunkStream.ts
Expand Up @@ -19,7 +19,7 @@ export async function* getChunkStream<T>(
currentBuffer.chunks.push(datum);
currentBuffer.length += datum.byteLength;

while (currentBuffer.length >= partSize) {
while (currentBuffer.length > partSize) {
/**
* Concat all the buffers together once if there is more than one to concat. Attempt
* to minimize concats as Buffer.Concat is an extremely expensive operation.
Expand Down
9 changes: 9 additions & 0 deletions lib/lib-storage/src/chunks/getDataReadableStream.spec.ts
Expand Up @@ -44,6 +44,15 @@ describe("chunkFromReadable.name", () => {
expect(chunks[0].lastPart).toBe(true);
});

it("should a single chunk if the stream is equal to partsize", async () => {
const chunks = await getChunks(20, 5, 100);

expect(chunks.length).toBe(1);
expect(byteLength(chunks[0].data)).toEqual(100);
expect(chunks[0].partNumber).toEqual(1);
expect(chunks[0].lastPart).toBe(true);
});

it("should return chunks of a specific size", async () => {
const chunks = await getChunks(58, 1, 20);

Expand Down

0 comments on commit a71cbd1

Please sign in to comment.