fs: use fs.writev() internally
Avoid using internal API in fs implementation. PR-URL: https://github.com/nodejs/node/pull/29189 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
5116a6a9b4
commit
490ec9b9c9
@ -2,10 +2,6 @@
|
|||||||
|
|
||||||
const { Math, Object } = primordials;
|
const { Math, Object } = primordials;
|
||||||
|
|
||||||
const {
|
|
||||||
FSReqCallback,
|
|
||||||
writeBuffers
|
|
||||||
} = internalBinding('fs');
|
|
||||||
const {
|
const {
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
ERR_OUT_OF_RANGE
|
ERR_OUT_OF_RANGE
|
||||||
@ -325,18 +321,6 @@ WriteStream.prototype._write = function(data, encoding, cb) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function writev(fd, chunks, position, callback) {
|
|
||||||
function wrapper(err, written) {
|
|
||||||
// Retain a reference to chunks so that they can't be GC'ed too soon.
|
|
||||||
callback(err, written || 0, chunks);
|
|
||||||
}
|
|
||||||
|
|
||||||
const req = new FSReqCallback();
|
|
||||||
req.oncomplete = wrapper;
|
|
||||||
writeBuffers(fd, chunks, position, req);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
WriteStream.prototype._writev = function(data, cb) {
|
WriteStream.prototype._writev = function(data, cb) {
|
||||||
if (typeof this.fd !== 'number') {
|
if (typeof this.fd !== 'number') {
|
||||||
return this.once('open', function() {
|
return this.once('open', function() {
|
||||||
@ -356,7 +340,7 @@ WriteStream.prototype._writev = function(data, cb) {
|
|||||||
size += chunk.length;
|
size += chunk.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
writev(this.fd, chunks, this.pos, function(er, bytes) {
|
fs.writev(this.fd, chunks, this.pos, function(er, bytes) {
|
||||||
if (er) {
|
if (er) {
|
||||||
self.destroy();
|
self.destroy();
|
||||||
return cb(er);
|
return cb(er);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user