mirror of
https://github.com/jprichardson/node-fs-extra.git
synced 2026-01-18 16:13:55 +00:00
Use Buffer.allocUnsafe() in enviroments that support it
This commit is contained in:
parent
84717b8d03
commit
a86d8b4ba1
@ -3,7 +3,7 @@
|
||||
const fs = require('graceful-fs')
|
||||
|
||||
const BUF_LENGTH = 64 * 1024
|
||||
const _buff = new Buffer(BUF_LENGTH)
|
||||
const _buff = require('../util/buffer')(BUF_LENGTH)
|
||||
|
||||
function copyFileSync (srcFile, destFile, options) {
|
||||
const overwrite = options.overwrite
|
||||
|
||||
@ -5,6 +5,7 @@ const path = require('path')
|
||||
const copySync = require('../copy-sync').copySync
|
||||
const removeSync = require('../remove').removeSync
|
||||
const mkdirpSync = require('../mkdirs').mkdirsSync
|
||||
const buffer = require('../util/buffer')
|
||||
|
||||
function moveSync (src, dest, options) {
|
||||
options = options || {}
|
||||
@ -60,7 +61,7 @@ function moveSyncAcrossDevice (src, dest, overwrite) {
|
||||
|
||||
function moveFileSyncAcrossDevice (src, dest, overwrite) {
|
||||
const BUF_LENGTH = 64 * 1024
|
||||
const _buff = new Buffer(BUF_LENGTH)
|
||||
const _buff = buffer(BUF_LENGTH)
|
||||
|
||||
const flags = overwrite ? 'w' : 'wx'
|
||||
|
||||
|
||||
10
lib/util/buffer.js
Normal file
10
lib/util/buffer.js
Normal file
@ -0,0 +1,10 @@
|
||||
module.exports = function (size) {
|
||||
if (typeof Buffer.allocUnsafe === 'function') {
|
||||
try {
|
||||
return Buffer.allocUnsafe(size)
|
||||
} catch (e) {
|
||||
return new Buffer(size)
|
||||
}
|
||||
}
|
||||
return new Buffer(size)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user