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

Function readUint8ArrayHttpReader

index-native.cjs:2781–2812  ·  view source on GitHub ↗
(httpReader, index, length, sendRequest, getRequestData)

Source from the content-addressed store, hash-verified

2779}
2780
2781async function readUint8ArrayHttpReader(httpReader, index, length, sendRequest, getRequestData) {
2782 const {
2783 useRangeHeader,
2784 forceRangeRequests,
2785 eocdCache,
2786 size,
2787 options
2788 } = httpReader;
2789 if (useRangeHeader || forceRangeRequests) {
2790 if (eocdCache && index == size - END_OF_CENTRAL_DIR_LENGTH && length == END_OF_CENTRAL_DIR_LENGTH) {
2791 return eocdCache;
2792 }
2793 if (index >= size || length === 0) {
2794 return new Uint8Array();
2795 } else {
2796 if (index + length > size) {
2797 length = size - index;
2798 }
2799 const response = await sendRequest(HTTP_METHOD_GET, httpReader, getRangeHeaders(httpReader, index, length));
2800 if (response.status != 206) {
2801 throw new Error(ERR_HTTP_RANGE);
2802 }
2803 return new Uint8Array(await response.arrayBuffer());
2804 }
2805 } else {
2806 const { data } = httpReader;
2807 if (!data) {
2808 await getRequestData(httpReader, options);
2809 }
2810 return new Uint8Array(httpReader.data.subarray(index, index + length));
2811 }
2812}
2813
2814function getRangeHeaders(httpReader, index = 0, length = 1) {
2815 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…