diff --git a/index.js b/index.js index 2ecd6f5..85204d5 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,14 @@ module.exports = function reverse (src) { var buffer = new Buffer(src.length) - for (var i = 0, j = src.length - 1; i <= j; ++i, --j) { - buffer[i] = src[j] - buffer[j] = src[i] - } + if (typeof buffer.reverse === "function") { + return buffer.reverse() + } else { + for (var i = 0, j = src.length - 1; i <= j; ++i, --j) { + buffer[i] = src[j] + buffer[j] = src[i] + } - return buffer + return buffer + } }