Skip to content

Commit 9466c82

Browse files
MR-BHxuyicun
and
xuyicun
authored
fix(lib-storage): send a single chunk if the stream is equal to partsize (#5036)
Co-authored-by: xuyicun <[email protected]>
1 parent d6c6982 commit 9466c82

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/lib-storage/src/chunks/getChunkStream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function* getChunkStream<T>(
1919
currentBuffer.chunks.push(datum);
2020
currentBuffer.length += datum.byteLength;
2121

22-
while (currentBuffer.length >= partSize) {
22+
while (currentBuffer.length > partSize) {
2323
/**
2424
* Concat all the buffers together once if there is more than one to concat. Attempt
2525
* to minimize concats as Buffer.Concat is an extremely expensive operation.

lib/lib-storage/src/chunks/getDataReadableStream.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ describe("chunkFromReadable.name", () => {
4444
expect(chunks[0].lastPart).toBe(true);
4545
});
4646

47+
it("should a single chunk if the stream is equal to partsize", async () => {
48+
const chunks = await getChunks(20, 5, 100);
49+
50+
expect(chunks.length).toBe(1);
51+
expect(byteLength(chunks[0].data)).toEqual(100);
52+
expect(chunks[0].partNumber).toEqual(1);
53+
expect(chunks[0].lastPart).toBe(true);
54+
});
55+
4756
it("should return chunks of a specific size", async () => {
4857
const chunks = await getChunks(58, 1, 20);
4958

0 commit comments

Comments
 (0)