Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,18 @@ function asBuffer(thing) {
return thing;
}

return Buffer.from ? Buffer.from(thing) : new Buffer(thing);
if (Buffer.from) {
// Buffer.from fix for node versions prior to 4.5.x
try {
return Buffer.from(thing);
} catch (e) {
if (e instanceof TypeError) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying to minimize the scope of errors that we'll try to catch.

return new Buffer(thing);
} else {
throw e;
}
}
} else {
return new Buffer(thing);
}
}