(httpReader, index, length, sendRequest, getRequestData)
| 2783 | } |
| 2784 | |
| 2785 | async 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 | |
| 2818 | function 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)) }); |
no test coverage detected
searching dependent graphs…