Buffers

Learn how to read and write using buffers in Deno.

Buffers in Deno

Buffers represent regions in memory that are used to store temporary binary data. They are commonly used to deal with I/O and network operations. Because asynchronous operations are something where Deno excels, we’ll explore buffers in this lesson.

Press + to interact
Buffer working
Buffer working

Deno buffers differ from Node.js buffers. This happens because when Node.js was created, and up until version 4, there was no support in JavaScript for ArrayBuffers. As Node.js optimized for asynchronous operations (where buffers really shine), the team behind it had to create a Node.js buffer to emulate the behavior of a native buffer. Later, ArrayBuffers were added into the language, and the Node.js team migrated the existing buffer to leverage it. It currently isn’t more than a subclass of ArrayBuffers. This same buffer was then deprecated in v10 of Node.js. Because Deno was recently created, its buffer deeply leverages ArrayBuffer.

Reading and writing from Deno.Buffer

Deno provides a dynamic length buffer that is implemented on top of ArrayBuffer, a fixed memory allocation. Buffers provide functionality similar ...