for (i = 0; i < length; i++) {
if (Buffer.isBuffer(subject))
buf[i] = subject.readUInt8(i)
- else
- buf.writeInt8(subject[i], i)
+ else {
+ if (subject[i] < 0)
+ buf[i] = subject[i] + 256
+ else
+ buf[i] = subject[i]
+ }
}
} else if (type === 'string') {
buf.write(subject, 0, encoding)
t.end()
})
+test('new buffer from array with mixed signed input', function (t) {
+ t.equal(
+ new B([-255, 255, -128, 128, 512, -512, 511, -511]).toString('hex'),
+ '01ff80800000ff01'
+ )
+ t.end()
+})
+
test('new buffer from string', function (t) {
t.equal(
new B('hey', 'utf8').toString(),