Socket
Socket
Sign inDemoInstall

buffer-from

Package Overview
Dependencies
46
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

60

index.js

@@ -0,1 +1,47 @@

var isArrayBuffer = require('is-array-buffer-x')
var isModern = (
typeof Buffer.alloc === 'function' &&
typeof Buffer.allocUnsafe === 'function' &&
typeof Buffer.from === 'function'
)
function fromArrayBuffer (obj, byteOffset, length) {
byteOffset >>>= 0
var maxLength = obj.byteLength - byteOffset
if (maxLength < 0) {
throw new RangeError("'offset' is out of bounds")
}
if (length === undefined) {
length = maxLength
} else {
length >>>= 0
if (length > maxLength) {
throw new RangeError("'length' is out of bounds")
}
}
return isModern
? Buffer.from(obj.slice(byteOffset, byteOffset + length))
: new Buffer(new Uint8Array(obj.slice(byteOffset, byteOffset + length)))
}
function fromString (string, encoding) {
if (typeof encoding !== 'string' || encoding === '') {
encoding = 'utf8'
}
if (!Buffer.isEncoding(encoding)) {
throw new TypeError('"encoding" must be a valid string encoding')
}
return isModern
? Buffer.from(string, encoding)
: new Buffer(string, encoding)
}
function bufferFrom (value, encodingOrOffset, length) {

@@ -6,5 +52,15 @@ if (typeof value === 'number') {

return new Buffer(value, encodingOrOffset, length)
if (isArrayBuffer(value)) {
return fromArrayBuffer(value, encodingOrOffset, length)
}
if (typeof value === 'string') {
return fromString(value, encodingOrOffset)
}
return isModern
? Buffer.from(value)
: new Buffer(value)
}
module.exports = (Buffer.from || bufferFrom)
module.exports = bufferFrom

7

package.json
{
"name": "buffer-from",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",

@@ -15,3 +15,6 @@ "repository": "LinusU/buffer-from",

"buffer from"
]
],
"dependencies": {
"is-array-buffer-x": "^1.0.13"
}
}
# Buffer From
A ponyfill for `Buffer.from`, uses native implementation if available.
A [ponyfill](https://ponyfill.com) for `Buffer.from`, uses native implementation if available.

@@ -5,0 +5,0 @@ ## Installation

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc