* pdf.js coalesces adjacent missing chunks into one unbounded request, but * readPdfRange clamps each call to MAX_CHUNK_BYTES. Its reader is keyed by * the original `begin` and removed after one delivery, so we must accumulate * slices and call onDataRange exactly once with the full buffer.
(begin: number, end: number)
| 928 | * slices and call onDataRange exactly once with the full buffer. |
| 929 | */ |
| 930 | private async deliver(begin: number, end: number): Promise<void> { |
| 931 | const buf = new Uint8Array(end - begin); |
| 932 | let off = 0; |
| 933 | while (off < buf.length) { |
| 934 | const want = Math.min(buf.length - off, MAX_CHUNK_BYTES); |
| 935 | const { data } = await this.readPdfRange(this.url, begin + off, want); |
| 936 | if (data.length === 0) { |
| 937 | throw new Error(`empty range at ${begin + off} for ${this.url}`); |
| 938 | } |
| 939 | buf.set(data.subarray(0, Math.min(data.length, buf.length - off)), off); |
| 940 | off += data.length; |
| 941 | } |
| 942 | this.onDataRange(begin, buf); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | // ============================================================================= |
no test coverage detected