Skip to content
Closed
Prev Previous commit
Next Next commit
fixup! buffer: refactor to remove some duplicated code in fromObject.
  • Loading branch information
entertainyou committed Jan 31, 2016
commit cdaa4ea4093c0c1d47df323e7062af5eabe21d96
15 changes: 7 additions & 8 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ function fromString(string, encoding) {
return b;
}

function fromArrayLike(obj) {
const length = obj.length;
const b = allocate(length);
for (let i = 0; i < length; i++)
b[i] = obj[i] & 255;
return b;
}

function fromObject(obj) {
if (obj instanceof Buffer) {
Expand All @@ -138,14 +145,6 @@ function fromObject(obj) {
throw new TypeError('Must start with number, buffer, array or string');
}

function fromArrayLike(obj) {
const length = obj.length;
const b = allocate(length);
for (let i = 0; i < length; i++)
b[i] = obj[i] & 255;
return b;
}

if (Array.isArray(obj)) {
return fromArrayLike(obj);
}
Expand Down