The module's API is identical to node's Buffer API. Read the
official docs for the full list of properties,
instance methods, and class methods that are supported.

As mentioned above, require('buffer') or use the Buffer global with
browserify and this module will automatically be included
in your bundle. Almost any npm module will work in the browser, even if it assumes that
the node Buffer API will be available.

To depend on this module explicitly (without browserify), require it like this:

To require this module explicitly, use require('buffer/') which tells the node.js module
lookup algorithm (also used by browserify) to use the npm module named buffer
instead of the node.js core module named buffer!

The Buffer constructor returns instances of Uint8Array that are augmented with function properties for all the Buffer API functions. We use Uint8Array so that square bracket notation works as expected -- it returns a single octet. By augmenting the instances, we can avoid modifying the Uint8Array prototype.

The Buffer constructor returns a Uint8Array (with all the Buffer methods added as
properties on the instance) for performance reasons, so instanceof Buffer won't work. In
node, you can use either Buffer.isBuffer or instanceof Buffer to check if an object
is a Buffer. But, in the browser you must use Buffer.isBuffer to detect the special
Uint8Array-based Buffers.

If you only support modern browsers (specifically, those with typed array support), then
this issue does not affect you.

In node, the slice() method returns a new Buffer that shares underlying memory with
the original Buffer. When you modify one buffer, you modify the other. Read more.

This works correctly in browsers with typed array support (* with the exception of Firefox older than version 30). Browsers that lack typed arrays get an alternate buffer implementation based on Object which has no mechanism to point separate Buffers to the same underlying slab of memory.

* Firefox older than version 30 gets the Object implementation -- not the typed arrays one -- because of this
bug (now fixed!) that made it impossible to add properties to a typed array.

This module tracks the Buffer API in the latest (unstable) version of node.js. The Buffer
API is considered stable in the
node stability index,
so it is unlikely that there will ever be breaking changes.
Nonetheless, when/if the Buffer API changes in node, this module's API will change
accordingly.

BrowserBuffer is the browser buffer module (this repo). Uint8Array is included as a
sanity check (since BrowserBuffer uses Uint8Array under the hood, Uint8Array will
always be at least a bit faster). Finally, NodeBuffer is the node.js buffer module,
which is included to compare against.