MCPcopy Create free account
hub / github.com/modelcontextprotocol/ext-apps / deliver

Method deliver

examples/pdf-server/server.ts:930–943  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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// =============================================================================

Callers 1

requestDataRangeMethod · 0.95

Calls 1

readPdfRangeMethod · 0.80

Tested by

no test coverage detected