diff options
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -321,7 +321,7 @@ ReadFileContext.prototype.read = function() { var length; if (this.size === 0) { - buffer = this.buffer = new SlowBuffer(kReadFileBufferLength); + buffer = this.buffer = SlowBuffer(kReadFileBufferLength); offset = 0; length = kReadFileBufferLength; } else { @@ -389,7 +389,7 @@ function readFileAfterStat(err, st) { return context.close(err); } - context.buffer = new SlowBuffer(size); + context.buffer = SlowBuffer(size); context.read(); } @@ -486,7 +486,7 @@ fs.readFileSync = function(path, options) { } else { threw = true; try { - buffer = new Buffer(size); + buffer = Buffer.allocUnsafe(size); threw = false; } finally { if (threw && !isUserFd) fs.closeSync(fd); @@ -504,7 +504,7 @@ fs.readFileSync = function(path, options) { } else { // the kernel lies about many files. // Go ahead and try to read some bytes. - buffer = new Buffer(8192); + buffer = Buffer.allocUnsafe(8192); bytesRead = fs.readSync(fd, buffer, 0, 8192); if (bytesRead) { buffers.push(buffer.slice(0, bytesRead)); @@ -635,7 +635,7 @@ fs.read = function(fd, buffer, offset, length, position, callback) { position = arguments[2]; length = arguments[1]; - buffer = new Buffer(length); + buffer = Buffer.allocUnsafe(length); offset = 0; callback = function(err, bytesRead) { @@ -695,7 +695,7 @@ fs.readSync = function(fd, buffer, offset, length, position) { position = arguments[2]; length = arguments[1]; - buffer = new Buffer(length); + buffer = Buffer.allocUnsafe(length); offset = 0; } @@ -1260,8 +1260,8 @@ fs.writeFile = function(path, data, options, callback_) { }); function writeFd(fd, isUserFd) { - var buffer = (data instanceof Buffer) ? data : new Buffer('' + data, - options.encoding || 'utf8'); + var buffer = (data instanceof Buffer) ? + data : Buffer.from('' + data, options.encoding || 'utf8'); var position = /a/.test(flag) ? null : 0; writeAll(fd, isUserFd, buffer, 0, buffer.length, position, callback); @@ -1284,7 +1284,7 @@ fs.writeFileSync = function(path, data, options) { var fd = isUserFd ? path : fs.openSync(path, flag, options.mode); if (!(data instanceof Buffer)) { - data = new Buffer('' + data, options.encoding || 'utf8'); + data = Buffer.from('' + data, options.encoding || 'utf8'); } var offset = 0; var length = data.length; @@ -1738,7 +1738,7 @@ fs.realpath = function realpath(p, cache, cb) { var pool; function allocNewPool(poolSize) { - pool = new Buffer(poolSize); + pool = Buffer.allocUnsafe(poolSize); pool.used = 0; } @@ -2108,7 +2108,7 @@ SyncWriteStream.prototype.write = function(data, arg1, arg2) { // Change strings to buffers. SLOW if (typeof data === 'string') { - data = new Buffer(data, encoding); + data = Buffer.from(data, encoding); } fs.writeSync(this.fd, data, 0, data.length); |