From 0dec5684566db37c96d7e28e5bebd0849bdc8dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D0=B2=D0=BE=D1=80=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=90=D0=BD=D0=B4=D1=80?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2=D0=B8=D1=87?= Date: Sun, 29 Apr 2018 20:58:29 +0300 Subject: [PATCH] fs: remove broken code in promises/write That code expects the last argument to be a callback. When it's not a callback, it shifts arguments, defaulting encoding to 'utf-8', which is clearly broken. Old signature: (fd, string[, position[, encoding]], callback) New signature: (fd, string[, position[, encoding]]) PR-URL: https://github.com/nodejs/node/pull/20407 Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Colin Ihrig Reviewed-By: Jamie Davis Reviewed-By: Sakthipriyan Vairamani --- lib/internal/fs/promises.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index b5543c79928751..3afd1a84985781 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -242,15 +242,6 @@ async function write(handle, buffer, offset, length, position) { if (typeof buffer !== 'string') buffer += ''; - if (typeof position !== 'function') { - if (typeof offset === 'function') { - position = offset; - offset = null; - } else { - position = length; - } - length = 'utf8'; - } const bytesWritten = (await binding.writeString(handle.fd, buffer, offset, length, kUsePromises)) || 0; return { bytesWritten, buffer };