Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
Last active May 26, 2019 18:58
Show Gist options
  • Select an option

  • Save vbarbarosh/21a45d9f995f225250b81e6a20b87f94 to your computer and use it in GitHub Desktop.

Select an option

Save vbarbarosh/21a45d9f995f225250b81e6a20b87f94 to your computer and use it in GitHub Desktop.
node_buffer – How to work with Buffer https://codescreens.com
// How to work with Buffer
main().catch(panic);
async function main()
{
// Use this if buffer will be immediately written to
Buffer.allocUnsafe(1024);
// Use this to allocate memory filled with zeroes
Buffer.alloc(1024);
// Use this to get a narrow view to the same memory
Buffer.alloc(1024).slice(0, 100);
}
function panic(error)
{
console.error(error);
process.exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment