summaryrefslogtreecommitdiff
path: root/lib/fs.js
diff options
context:
space:
mode:
authorSakthipriyan Vairamani (thefourtheye) <thechargingvolcano@gmail.com>2018-10-17 14:40:08 +0530
committerRich Trott <rtrott@gmail.com>2018-12-15 12:54:50 -0800
commit8f4b924f4a7b37bd16ddff65329c8e96fc5f0f2d (patch)
tree5e7c42bff1a19117507ddd239b8acebe6ca10016 /lib/fs.js
parent2c5dae59341aafc69e1edd62555e6942ba8f0d50 (diff)
downloadnode-new-8f4b924f4a7b37bd16ddff65329c8e96fc5f0f2d.tar.gz
fs: make writeFile consistent with readFile wrt fd
As it is, `readFile` always reads from the current position of the file, if a file descriptor is used. But `writeFile` always writes from the beginning of the file. This patch fixes this inconsistency by making `writeFile` also to write from the current position of the file when used with a file descriptor. PR-URL: https://github.com/nodejs/node/pull/23709 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/fs.js')
-rw-r--r--lib/fs.js4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 335b164483..873e93d9cd 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1229,7 +1229,7 @@ function writeFile(path, data, options, callback) {
function writeFd(fd, isUserFd) {
const buffer = isArrayBufferView(data) ?
data : Buffer.from('' + data, options.encoding || 'utf8');
- const position = /a/.test(flag) ? null : 0;
+ const position = (/a/.test(flag) || isUserFd) ? null : 0;
writeAll(fd, isUserFd, buffer, 0, buffer.byteLength, position, callback);
}
@@ -1247,7 +1247,7 @@ function writeFileSync(path, data, options) {
}
let offset = 0;
let length = data.byteLength;
- let position = /a/.test(flag) ? null : 0;
+ let position = (/a/.test(flag) || isUserFd) ? null : 0;
try {
while (length > 0) {
const written = fs.writeSync(fd, data, offset, length, position);