MCPcopy
hub / github.com/gildas-lormeau/zip.js / readUint8ArrayHttpReader

Function readUint8ArrayHttpReader

index.cjs:2785–2816  ·  view source on GitHub ↗
(httpReader, index, length, sendRequest, getRequestData)

Source from the content-addressed store, hash-verified

2783}
2784
2785async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
2786 const {
2787 useRangeHeader,
2788 forceRangeRequests,
2789 eocdCache,
2790 size,
2791 options
2792 } = httpReader;
2793 if (useRangeHeader || forceRangeRequests) {
2794 if (eocdCache && index == size - END_OF_CENTRAL_DIR_LENGTH && length == END_OF_CENTRAL_DIR_LENGTH) {
2795 return eocdCache;
2796 }
2797 if (index >= size || length === 0) {
2798 return new Uint8Array();
2799 } else {
2800 if (index + length > size) {
2801 length = size - index;
2802 }
2803 const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
2804 if (response.status != 206) {
2805 throw new Error(ERR_HTTP_RANGE);
2806 }
2807 return new Uint8Array(await response.arrayBuffer());
2808 }
2809 } else {
2810 const { data } = httpReader;
2811 if (!data) {
2812 await getRequestData(httpReader, options);
2813 }
2814 return new Uint8Array(httpReader.data.subarray(index, index + length));
2815 }
2816}
2817
2818function getRangeHeaders(httpReader, index = 0, length = 1) {
2819 return Object.assign({}, getHeaders(httpReader), { [HTTP_HEADER_RANGE]: HTTP_RANGE_UNIT + "=" + (index < 0 ? index : index + "-" + (index + length - 1)) });

Callers 2

readUint8ArrayMethod · 0.70
readUint8ArrayMethod · 0.70

Calls 3

arrayBufferMethod · 0.80
getRangeHeadersFunction · 0.70
getRequestDataFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…