1 /* eslint-disable node/no-deprecated-api */
5 var buffer = require('buffer')
6 var Buffer = buffer.Buffer
7 var safer = require('./safer.js')
8 var Safer = safer.Buffer
15 if (!safer.hasOwnProperty(key)) continue
16 dangerous[key] = safer[key]
19 var Dangereous = dangerous.Buffer = {}
23 if (!Safer.hasOwnProperty(key)) continue
24 Dangereous[key] = Safer[key]
27 // Copy those missing unsafe methods, if they are present
29 if (!Buffer.hasOwnProperty(key)) continue
30 if (Dangereous.hasOwnProperty(key)) continue
31 Dangereous[key] = Buffer[key]
34 if (!Dangereous.allocUnsafe) {
35 Dangereous.allocUnsafe = function (size) {
36 if (typeof size !== 'number') {
37 throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size)
39 if (size < 0 || size >= 2 * (1 << 30)) {
40 throw new RangeError('The value "' + size + '" is invalid for option "size"')
46 if (!Dangereous.allocUnsafeSlow) {
47 Dangereous.allocUnsafeSlow = function (size) {
48 if (typeof size !== 'number') {
49 throw new TypeError('The "size" argument must be of type number. Received type ' + typeof size)
51 if (size < 0 || size >= 2 * (1 << 30)) {
52 throw new RangeError('The value "' + size + '" is invalid for option "size"')
54 return buffer.SlowBuffer(size)
58 module.exports = dangerous