(self, handle, buf, off, len, position, cb, req_)
| 2099 | } |
| 2100 | |
| 2101 | function read_(self, handle, buf, off, len, position, cb, req_) { |
| 2102 | const maxDataLen = self._maxReadLen; |
| 2103 | const overflow = Math.max(len - maxDataLen, 0); |
| 2104 | |
| 2105 | if (overflow) |
| 2106 | len = maxDataLen; |
| 2107 | |
| 2108 | /* |
| 2109 | uint32 id |
| 2110 | string handle |
| 2111 | uint64 offset |
| 2112 | uint32 len |
| 2113 | */ |
| 2114 | const handleLen = handle.length; |
| 2115 | let p = 9; |
| 2116 | let pos = position; |
| 2117 | const out = Buffer.allocUnsafe(4 + 1 + 4 + 4 + handleLen + 8 + 4); |
| 2118 | |
| 2119 | writeUInt32BE(out, out.length - 4, 0); |
| 2120 | out[4] = REQUEST.READ; |
| 2121 | const reqid = self._writeReqid = (self._writeReqid + 1) & MAX_REQID; |
| 2122 | writeUInt32BE(out, reqid, 5); |
| 2123 | |
| 2124 | writeUInt32BE(out, handleLen, p); |
| 2125 | out.set(handle, p += 4); |
| 2126 | p += handleLen; |
| 2127 | for (let i = 7; i >= 0; --i) { |
| 2128 | out[p + i] = pos & 0xFF; |
| 2129 | pos /= 256; |
| 2130 | } |
| 2131 | writeUInt32BE(out, len, p += 8); |
| 2132 | |
| 2133 | if (typeof cb !== 'function') |
| 2134 | cb = noop; |
| 2135 | |
| 2136 | const req = (req_ || { |
| 2137 | nb: 0, |
| 2138 | position, |
| 2139 | off, |
| 2140 | origOff: off, |
| 2141 | len: undefined, |
| 2142 | overflow: undefined, |
| 2143 | cb: (err, data, nb) => { |
| 2144 | const len = req.len; |
| 2145 | const overflow = req.overflow; |
| 2146 | |
| 2147 | if (err) { |
| 2148 | if (cb._wantEOFError || err.code !== STATUS_CODE.EOF) |
| 2149 | return cb(err); |
| 2150 | } else if (nb > len) { |
| 2151 | return cb(new Error('Received more data than requested')); |
| 2152 | } else if (nb === len && overflow) { |
| 2153 | req.nb += nb; |
| 2154 | req.position += nb; |
| 2155 | req.off += nb; |
| 2156 | read_(self, handle, buf, req.off, overflow, req.position, cb, req); |
| 2157 | return; |
| 2158 | } |
no test coverage detected
searching dependent graphs…