We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 540abd6 commit ef6aeb4Copy full SHA for ef6aeb4
index.js
@@ -1,8 +1,9 @@
1
+var Buffer = require('safe-buffer').Buffer
2
module.exports = function reverse (src) {
3
if (typeof src.reverse === 'function') {
- return src.reverse()
4
+ return Buffer.from(src).reverse()
5
} else {
- var buffer = new Buffer(src.length)
6
+ var buffer = Buffer.alloc(src.length)
7
8
for (var i = 0, j = src.length - 1; i <= j; ++i, --j) {
9
buffer[i] = src[j]
package.json
@@ -37,5 +37,8 @@
37
"devDependencies": {
38
"standard": "*",
39
"tape": "*"
40
+ },
41
+ "dependencies": {
42
+ "safe-buffer": "^5.1.1"
43
}
44
test/index.js
@@ -1,3 +1,4 @@
var test = require('tape')
var reverse = require('../')
var reverseInplace = require('../inplace')
@@ -6,7 +7,7 @@ var fixtures = require('./fixtures')
test('reverse', function (t) {
fixtures.forEach(function (f) {
t.test('returns ' + f.expected + ' for ' + f.a, function (t) {
- var a = new Buffer(f.a, 'hex')
10
+ var a = Buffer.from(f.a, 'hex')
11
t.same(reverse(a).toString('hex'), f.expected)
12
t.same(a.toString('hex'), f.a) // input unchanged
13
t.end()
@@ -19,7 +20,7 @@ test('reverse', function (t) {
19
20
test('reverse/inplace', function (t) {
21
22
23
24
t.same(reverseInplace(a).toString('hex'), f.expected)
25
t.same(a.toString('hex'), f.expected) // input mutated
26
0 commit comments