Skip to content

Commit

Permalink
Merge pull request #15 from calvinmetcalf/no-object-keys
Browse files Browse the repository at this point in the history
remove object keys, because we can't have nice things
  • Loading branch information
feross authored Jun 21, 2017
2 parents 9d841b6 + e6aba51 commit a986c46
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
var buffer = require('buffer')
var Buffer = buffer.Buffer

// alternative to using Object.keys for old browsers
function copyProps (src, dst) {
for (var key in src) {
dst[key] = src[key]
}
}
if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
module.exports = buffer
} else {
// Copy properties from require('buffer')
Object.keys(buffer).forEach(function (prop) {
exports[prop] = buffer[prop]
})
copyProps(buffer, exports)
exports.Buffer = SafeBuffer
}

Expand All @@ -17,9 +21,7 @@ function SafeBuffer (arg, encodingOrOffset, length) {
}

// Copy static methods from Buffer
Object.keys(Buffer).forEach(function (prop) {
SafeBuffer[prop] = Buffer[prop]
})
copyProps(Buffer, SafeBuffer)

SafeBuffer.from = function (arg, encodingOrOffset, length) {
if (typeof arg === 'number') {
Expand Down

0 comments on commit a986c46

Please sign in to comment.