Skip to content

Commit 476ce3d

Browse files
committed
Fixed a bug where isEndOfStream would not work correctly for BinaryReaders created from Uint8Array, which had non-zero byte offset or smaller length than the underlaying buffer
1 parent 6d64183 commit 476ce3d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/BinaryReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class BinaryReader
5353
*/
5454
public get isEndOfStream(): boolean
5555
{
56-
return this._position >= this._stream.byteLength;
56+
return this._position >= this._bufferLength;
5757
}
5858

5959
private get internalPosition(): number

test/BinaryReader.misc.common.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,13 @@ describe("BinaryReader, common tests", () =>
8383
const reader = new BinaryReader(getBufferOfLength(0));
8484
expect(reader.isEndOfStream).to.equal(true);
8585
});
86+
it("Should return true when at the end of stream that has data outside the view", () =>
87+
{
88+
const buffer = new ArrayBuffer(16);
89+
const view = new Uint8Array(buffer, 4, 8);
90+
const reader = new BinaryReader(view);
91+
reader.position = 8;
92+
expect(reader.isEndOfStream).to.equal(true);
93+
});
8694
});
8795
});

0 commit comments

Comments
 (0)