package
Expand a buffer to a specified length
npm install buffer-expand@0.0.1
GitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Latest published Apr 6, 2017
latest
Registry package owners.
jprichardson
jprichardson@gmail.com
ryanzim
opensrc@ryanzim.com
Expand a buffer to a specified length. If the buffer is smaller than the specified length, the remaining space is filled with random bytes. A 32-bit Unsigned Big-Endian Integer containing the length of the data is always prepended to the buffer.
npm install buffer-expand
const size = 25 const { expand, shrink } = require('buffer-expand')(size) const data = Buffer.from('Hello World!') const newData = expand(data) console.log(data, newData) // Prints: // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64 21> // <Buffer 00 00 00 0c 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 91 5c d3 2f> assert(newData.length === size) assert(shrink(newData).equals(data))
MIT