You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
2 years ago
|
var root = require('./_root');
|
||
|
|
||
|
/** Detect free variable `exports`. */
|
||
|
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
|
||
|
|
||
|
/** Detect free variable `module`. */
|
||
|
var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
|
||
|
|
||
|
/** Detect the popular CommonJS extension `module.exports`. */
|
||
|
var moduleExports = freeModule && freeModule.exports === freeExports;
|
||
|
|
||
|
/** Built-in value references. */
|
||
|
var Buffer = moduleExports ? root.Buffer : undefined,
|
||
|
allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined;
|
||
|
|
||
|
/**
|
||
|
* Creates a clone of `buffer`.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {Buffer} buffer The buffer to clone.
|
||
|
* @param {boolean} [isDeep] Specify a deep clone.
|
||
|
* @returns {Buffer} Returns the cloned buffer.
|
||
|
*/
|
||
|
function cloneBuffer(buffer, isDeep) {
|
||
|
if (isDeep) {
|
||
|
return buffer.slice();
|
||
|
}
|
||
|
var length = buffer.length,
|
||
|
result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
|
||
|
|
||
|
buffer.copy(result);
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
module.exports = cloneBuffer;
|