Skip to content

Commit

Permalink
fix(lib-storage): send a single chunk if the stream is equal to parts…
Browse files Browse the repository at this point in the history
…ize (#5036)

Co-authored-by: xuyicun <xuyicun@lixiang.com>
  • Loading branch information
MR-BH and xuyicun authored May 15, 2024
1 parent d6c6982 commit 9466c82
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 9466c82

Please sign in to comment.