* Convert a Buffer or an Array of Buffers to an ArrayBuffer. * * If the input is an Array of Buffers, they will be concatenated in the * specified order to form the output ArrayBuffer. * * @param buf A Buffer or an Array of Buffers. * @return An ArrayBuffer.
(buf: Buffer|Buffer[])
| 130 | * @return An ArrayBuffer. |
| 131 | */ |
| 132 | function toArrayBuffer(buf: Buffer|Buffer[]): ArrayBuffer { |
| 133 | if (Array.isArray(buf)) { |
| 134 | const newBuf = Buffer.concat(buf); |
| 135 | |
| 136 | return newBuf.buffer.slice( |
| 137 | newBuf.byteOffset, newBuf.byteOffset + newBuf.byteLength); |
| 138 | } else { |
| 139 | // A single Buffer. Return a copy of the underlying ArrayBuffer slice. |
| 140 | return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength); |
| 141 | } |
| 142 | } |
no test coverage detected
searching dependent graphs…