Skip to content

Commit

Permalink
Merge branch 'master' into inspect-symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Aug 13, 2019
2 parents 5741b39 + e107169 commit 4516196
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 244 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: feross
tidelift: npm/buffer
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.airtap.yml
.github/
.travis.yml
bin/
perf/
test/
9 changes: 9 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,14 @@
- adventure-yunfei (adventure030@gmail.com)
- Emil Bay (github@tixz.dk)
- Sam Sudar (sudar.sam@gmail.com)
- Volker Mische (volker.mische@gmail.com)
- David Walton (support@geekstocks.com)
- Сковорода Никита Андреевич (chalkerx@gmail.com)
- greenkeeper[bot] (greenkeeper[bot]@users.noreply.github.com)
- ukstv (sergey.ukustov@machinomy.com)
- ranbochen (ranbochen@qq.com)
- Vladimir Borovik (bobahbdb@gmail.com)
- greenkeeper[bot] (23040076+greenkeeper[bot]@users.noreply.github.com)
- kumavis (aaron@kumavis.me)

#### Generated by bin/update-authors.sh.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ To use this module directly (without browserify), install it:
npm install buffer
```

[Get supported buffer with the Tidelift Subscription](https://tidelift.com/subscription/pkg/npm-buffer?utm_source=npm-buffer&utm_medium=referral&utm_campaign=readme)

This module was previously called **native-buffer-browserify**, but please use **buffer**
from now on.

A standalone bundle is available [here](https://wzrd.in/standalone/buffer), for non-browserify users.

If you do not use a bundler, you can use the [standalone script](https://bundle.run/buffer).

## usage

Expand Down
368 changes: 183 additions & 185 deletions index.d.ts

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ function typedArraySupport () {
// Can typed array instances can be augmented?
try {
var arr = new Uint8Array(1)
arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }}
var proto = { foo: function () { return 42 } }
Object.setPrototypeOf(proto, Uint8Array.prototype)
Object.setPrototypeOf(arr, proto)
return arr.foo() === 42
} catch (e) {
return false
Expand Down Expand Up @@ -76,7 +78,7 @@ function createBuffer (length) {
}
// Return an augmented `Uint8Array` instance
var buf = new Uint8Array(length)
buf.__proto__ = Buffer.prototype
Object.setPrototypeOf(buf, Buffer.prototype)
return buf
}

Expand Down Expand Up @@ -126,7 +128,7 @@ function from (value, encodingOrOffset, length) {
}

if (value == null) {
throw TypeError(
throw new TypeError(
'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
'or Array-like Object. Received type ' + (typeof value)
)
Expand Down Expand Up @@ -178,8 +180,8 @@ Buffer.from = function (value, encodingOrOffset, length) {

// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
// https://github.com/feross/buffer/pull/148
Buffer.prototype.__proto__ = Uint8Array.prototype
Buffer.__proto__ = Uint8Array
Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype)
Object.setPrototypeOf(Buffer, Uint8Array)

function assertSize (size) {
if (typeof size !== 'number') {
Expand Down Expand Up @@ -283,7 +285,8 @@ function fromArrayBuffer (array, byteOffset, length) {
}

// Return an augmented `Uint8Array` instance
buf.__proto__ = Buffer.prototype
Object.setPrototypeOf(buf, Buffer.prototype)

return buf
}

Expand Down Expand Up @@ -733,7 +736,7 @@ function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
}
}
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir)
}

throw new TypeError('val must be string, number or Buffer')
Expand Down Expand Up @@ -1099,7 +1102,8 @@ Buffer.prototype.slice = function slice (start, end) {

var newBuf = this.subarray(start, end)
// Return an augmented `Uint8Array` instance
newBuf.__proto__ = Buffer.prototype
Object.setPrototypeOf(newBuf, Buffer.prototype)

return newBuf
}

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "buffer",
"description": "Node.js Buffer API, for the browser",
"version": "5.1.0",
"version": "5.3.0",
"author": {
"name": "Feross Aboukhadijeh",
"email": "feross@feross.org",
Expand All @@ -20,18 +20,18 @@
"inspect-custom-symbol": "^1.1.0"
},
"devDependencies": {
"airtap": "0.0.5",
"airtap": "^2.0.3",
"benchmark": "^2.0.0",
"browserify": "^16.1.0",
"concat-stream": "^1.4.7",
"concat-stream": "^2.0.0",
"hyperquest": "^2.0.0",
"is-buffer": "^2.0.0",
"is-nan": "^1.0.1",
"split": "^1.0.0",
"standard": "*",
"tape": "^4.0.0",
"through2": "^2.0.0",
"uglify-js": "^3.3.12"
"through2": "^3.0.1",
"uglify-js": "^3.4.5"
},
"homepage": "https://github.com/feross/buffer",
"jspm": {
Expand Down
4 changes: 2 additions & 2 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ test('indexes from a string', function (t) {
})

test('indexes from an array', function (t) {
var buf = new B([ 97, 98, 99 ])
var buf = new B([97, 98, 99])
t.equal(buf[0], 97)
t.equal(buf[1], 98)
t.equal(buf[2], 99)
t.end()
})

test('setting index value should modify buffer contents', function (t) {
var buf = new B([ 97, 98, 99 ])
var buf = new B([97, 98, 99])
t.equal(buf[2], 99)
t.equal(buf.toString(), 'abc')

Expand Down
36 changes: 18 additions & 18 deletions test/from-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ test('detect utf16 surrogate pairs over U+20000 until U+10FFFF', function (t) {
test('replace orphaned utf16 surrogate lead code point', function (t) {
var text = '\uD83D\uDE38' + '\uD83D' + '\uD83D\uDC4D'
var buf = new B(text)
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d ]))
t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d]))
t.end()
})

test('replace orphaned utf16 surrogate trail code point', function (t) {
var text = '\uD83D\uDE38' + '\uDCAD' + '\uD83D\uDC4D'
var buf = new B(text)
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d ]))
t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xef, 0xbf, 0xbd, 0xf0, 0x9f, 0x91, 0x8d]))
t.end()
})

Expand All @@ -44,42 +44,42 @@ test('handle partial utf16 code points when encoding to utf8 the way node does',
var buf = new B(8)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0xf0, 0x9f, 0x91, 0x8d ]))
t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0xf0, 0x9f, 0x91, 0x8d]))

buf = new B(7)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00, 0x00 ]))
t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00, 0x00]))

buf = new B(6)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00 ]))
t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00, 0x00]))

buf = new B(5)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8, 0x00 ]))
t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8, 0x00]))

buf = new B(4)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0xf0, 0x9f, 0x98, 0xb8 ]))
t.deepEqual(buf, new B([0xf0, 0x9f, 0x98, 0xb8]))

buf = new B(3)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x00, 0x00, 0x00 ]))
t.deepEqual(buf, new B([0x00, 0x00, 0x00]))

buf = new B(2)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x00, 0x00 ]))
t.deepEqual(buf, new B([0x00, 0x00]))

buf = new B(1)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x00 ]))
t.deepEqual(buf, new B([0x00]))

t.end()
})
Expand All @@ -90,42 +90,42 @@ test('handle invalid utf16 code points when encoding to utf8 the way node does',
var buf = new B(8)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd, 0x62 ]))
t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd, 0x62]))

buf = new B(7)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd ]))
t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd]))

buf = new B(6)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0x00, 0x00 ]))
t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0x00, 0x00]))

buf = new B(5)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd, 0x00 ]))
t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd, 0x00]))

buf = new B(4)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x61, 0xef, 0xbf, 0xbd ]))
t.deepEqual(buf, new B([0x61, 0xef, 0xbf, 0xbd]))

buf = new B(3)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x61, 0x00, 0x00 ]))
t.deepEqual(buf, new B([0x61, 0x00, 0x00]))

buf = new B(2)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x61, 0x00 ]))
t.deepEqual(buf, new B([0x61, 0x00]))

buf = new B(1)
buf.fill(0)
buf.write(text)
t.deepEqual(buf, new B([ 0x61 ]))
t.deepEqual(buf, new B([0x61]))

t.end()
})
4 changes: 2 additions & 2 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test('buffer.toJSON', function (t) {
var data = [1, 2, 3, 4]
t.deepEqual(
new B(data).toJSON(),
{ type: 'Buffer', data: [ 1, 2, 3, 4 ] }
{ type: 'Buffer', data: [1, 2, 3, 4] }
)
t.end()
})
Expand Down Expand Up @@ -41,7 +41,7 @@ test('test offset returns are correct', function (t) {

test('concat() a varying number of buffers', function (t) {
var zero = []
var one = [ new B('asdf') ]
var one = [new B('asdf')]
var long = []
for (var i = 0; i < 10; i++) {
long.push(new B('asdf'))
Expand Down

0 comments on commit 4516196

Please sign in to comment.