* Returns buffer with bytes. * @param {number} n amount of bytes to read * @returns {Buffer} buffer with bytes
(n)
| 228 | * @returns {Buffer} buffer with bytes |
| 229 | */ |
| 230 | read(n) { |
| 231 | this.ensureBuffer(); |
| 232 | const rem = |
| 233 | /** @type {Buffer} */ (this.currentBuffer).length - this.currentPosition; |
| 234 | if (rem < n) { |
| 235 | const buffers = [this.read(rem)]; |
| 236 | n -= rem; |
| 237 | this.ensureBuffer(); |
| 238 | while (/** @type {Buffer} */ (this.currentBuffer).length < n) { |
| 239 | const b = /** @type {Buffer} */ (this.currentBuffer); |
| 240 | buffers.push(b); |
| 241 | n -= b.length; |
| 242 | this.nextDataItem(); |
| 243 | this.ensureBuffer(); |
| 244 | } |
| 245 | buffers.push(this.read(n)); |
| 246 | return Buffer.concat(buffers); |
| 247 | } |
| 248 | const b = /** @type {Buffer} */ (this.currentBuffer); |
| 249 | const res = Buffer.from(b.buffer, b.byteOffset + this.currentPosition, n); |
| 250 | this.currentPosition += n; |
| 251 | this.checkOverflow(); |
| 252 | return res; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Reads up to n bytes. |
no test coverage detected