(data)
| 187 | |
| 188 | // This handles incoming data to parse |
| 189 | push(data) { |
| 190 | if (data === null) { |
| 191 | cleanupRequests(this); |
| 192 | if (!this.readable) |
| 193 | return; |
| 194 | // No more incoming data from the remote side |
| 195 | this.readable = false; |
| 196 | this.emit('end'); |
| 197 | return; |
| 198 | } |
| 199 | /* |
| 200 | uint32 length |
| 201 | byte type |
| 202 | byte[length - 1] data payload |
| 203 | */ |
| 204 | let p = 0; |
| 205 | |
| 206 | while (p < data.length) { |
| 207 | if (this._pktLenBytes < 4) { |
| 208 | let nb = Math.min(4 - this._pktLenBytes, data.length - p); |
| 209 | this._pktLenBytes += nb; |
| 210 | |
| 211 | while (nb--) |
| 212 | this._pktLen = (this._pktLen << 8) + data[p++]; |
| 213 | |
| 214 | if (this._pktLenBytes < 4) |
| 215 | return; |
| 216 | if (this._pktLen === 0) |
| 217 | return doFatalSFTPError(this, 'Invalid packet length'); |
| 218 | if (this._pktLen > this._maxInPktLen) { |
| 219 | const max = this._maxInPktLen; |
| 220 | return doFatalSFTPError( |
| 221 | this, |
| 222 | `Packet length ${this._pktLen} exceeds max length of ${max}` |
| 223 | ); |
| 224 | } |
| 225 | if (p >= data.length) |
| 226 | return; |
| 227 | } |
| 228 | if (this._pktPos < this._pktLen) { |
| 229 | const nb = Math.min(this._pktLen - this._pktPos, data.length - p); |
| 230 | if (p !== 0 || nb !== data.length) { |
| 231 | if (nb === this._pktLen) { |
| 232 | this._pkt = new FastBuffer(data.buffer, data.byteOffset + p, nb); |
| 233 | } else { |
| 234 | if (!this._pkt) |
| 235 | this._pkt = Buffer.allocUnsafe(this._pktLen); |
| 236 | this._pkt.set( |
| 237 | new Uint8Array(data.buffer, data.byteOffset + p, nb), |
| 238 | this._pktPos |
| 239 | ); |
| 240 | } |
| 241 | } else if (nb === this._pktLen) { |
| 242 | this._pkt = data; |
| 243 | } else { |
| 244 | if (!this._pkt) |
| 245 | this._pkt = Buffer.allocUnsafe(this._pktLen); |
| 246 | this._pkt.set(data, this._pktPos); |
no test coverage detected