Skip to content

Commit bc51527

Browse files
committed
fix when regurgating duplicated data
1 parent e08718c commit bc51527

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/hub/src/utils/XetBlob.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("XetBlob", () => {
137137
expect(new Uint8Array(xetDownload)).toEqual(new Uint8Array(bridgeDownload));
138138
}, 30_000);
139139

140-
it("should load text correctly when offset_into_range starts in a chunk further than the first", async () => {
140+
it.only("should load text correctly when offset_into_range starts in a chunk further than the first", async () => {
141141
const blob = new XetBlob({
142142
repo: {
143143
type: "model",

packages/hub/src/utils/XetBlob.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class XetBlob extends Blob {
217217
const termRanges = rangeList.getRanges(term.range.start, term.range.end);
218218

219219
if (termRanges.every((range) => range.data)) {
220-
for (const range of termRanges) {
220+
rangeLoop: for (const range of termRanges) {
221221
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
222222
for (let chunk of range.data!) {
223223
if (chunk.length > maxBytes - totalBytesRead) {
@@ -227,6 +227,10 @@ export class XetBlob extends Blob {
227227
// The stream consumer can decide to transfer ownership of the chunk, so we need to return a clone
228228
// if there's more than one range for the same term
229229
yield range.refCount > 1 ? chunk.slice() : chunk;
230+
231+
if (totalBytesRead >= maxBytes) {
232+
break rangeLoop;
233+
}
230234
}
231235
}
232236
rangeList.remove(term.range.start, term.range.end);

0 commit comments

Comments
 (0)