From 175a6569f4f6f139d753f97de56d998dd2d46cf9 Mon Sep 17 00:00:00 2001 From: Jacob <3012099+JakobJingleheimer@users.noreply.github.com> Date: Sun, 27 Jun 2021 10:24:04 +0200 Subject: [PATCH] doc: add annotation to writeFile `data` as `Object` Fixes: https://github.com/nodejs/node/issues/39152 PR-URL: https://github.com/nodejs/node/pull/39167 Reviewed-By: Antoine du Hamel --- doc/api/fs.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index fa7dd3c70cb947..222686c555070e 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -440,6 +440,9 @@ changes: Write `buffer` to the file. +If `buffer` is a plain object, it must have an own (not inherited) `toString` +function property. + The promise is resolved with an object containing two properties: * `bytesWritten` {integer} the number of bytes written @@ -1284,8 +1287,8 @@ changes: * Returns: {Promise} Fulfills with `undefined` upon success. Asynchronously writes data to a file, replacing the file if it already exists. -`data` can be a string, a {Buffer}, or an object with an own `toString` function -property. +`data` can be a string, a {Buffer}, or, an object with an own (not inherited) +`toString` function property. The `encoding` option is ignored if `data` is a buffer. @@ -3937,7 +3940,9 @@ When `file` is a file descriptor, the behavior is similar to calling a file descriptor. The `encoding` option is ignored if `data` is a buffer. -If `data` is a normal object, it must have an own `toString` function property. + +If `data` is a plain object, it must have an own (not inherited) `toString` +function property. ```mjs import { writeFile } from 'fs'; @@ -5031,6 +5036,9 @@ changes: Returns `undefined`. +If `data` is a plain object, it must have an own (not inherited) `toString` +function property. + For detailed information, see the documentation of the asynchronous version of this API: [`fs.writeFile()`][]. @@ -5065,6 +5073,9 @@ changes: * `position` {integer} * Returns: {number} The number of bytes written. +If `buffer` is a plain object, it must have an own (not inherited) `toString` +function property. + For detailed information, see the documentation of the asynchronous version of this API: [`fs.write(fd, buffer...)`][]. @@ -5091,6 +5102,9 @@ changes: * `encoding` {string} * Returns: {number} The number of bytes written. +If `string` is a plain object, it must have an own (not inherited) `toString` +function property. + For detailed information, see the documentation of the asynchronous version of this API: [`fs.write(fd, string...)`][].