1 /* eslint-disable node/no-deprecated-api */
5 var buffer = require('buffer')
6 var Buffer = buffer.Buffer
13 if (!buffer.hasOwnProperty(key)) continue
14 if (key === 'SlowBuffer' || key === 'Buffer') continue
15 safer[key] = buffer[key]
18 var Safer = safer.Buffer = {}
20 if (!Buffer.hasOwnProperty(key)) continue
21 if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue
22 Safer[key] = Buffer[key]
25 safer.Buffer.prototype = Buffer.prototype
27 if (!Safer.from || Safer.from === Uint8Array.from) {
28 Safer.from = function (value, encodingOrOffset, length) {
29 if (typeof value === 'number') {
30 throw new TypeError('The "value" argument must not be of type number. Received type ' + typeof value)
32 if (value && typeof value.length === 'undefined') {
33 throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + typeof value)
35 return Buffer(value, encodingOrOffset, length)
40 Safer.alloc = function (size, fill, encoding) {
41 if (typeof size !== 'number') {
42 throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size)
44 if (size < 0 || size >= 2 * (1 << 30)) {
45 throw new RangeError('The value "' + size + '" is invalid for option "size"')
47 var buf = Buffer(size)
48 if (!fill || fill.length === 0) {
50 } else if (typeof encoding === 'string') {
51 buf.fill(fill, encoding)
59 if (!safer.kStringMaxLength) {
61 safer.kStringMaxLength = process.binding('buffer').kStringMaxLength
63 // we can't determine kStringMaxLength in environments where process.binding
64 // is unsupported, so let's not set it
68 if (!safer.constants) {
70 MAX_LENGTH: safer.kMaxLength
72 if (safer.kStringMaxLength) {
73 safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength
77 module.exports = safer