feross/buffer — pull request #31 by dcousens (2014-05-28 11:52:51+00:00)
Title: Fix of #30

In pull request #30, I added support negative numbers for when non-typed arrays didn't exist.
This was done by constraining the input to `[-128, 127]` (aka, `Buffer.writeInt8`), however this inadvertently disabled the ability for users to use byte arrays in the unsigned manner: `[0, 255]`.

To resolve this, I have attempted to replicate the behaviour found in the browser for native `UInt8Array`s, which appears to take the `mod 256` of the input (with behaviour for negative numbers wrapping around `[0, 256]`).

In accordance with http://stackoverflow.com/questions/4467539/javascript-modulo-not-behaving, I have constrained the space to `[-255, 255]`, added `256` (`[0, 512]`), then clamped it to `[0, 256]` again.

Hopefully this should suffice.