From 4455f603207815199854797b043b86cc8a885eb3 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 26 Sep 2019 14:13:49 +0200 Subject: [PATCH] doc: use shorter fs.copyFile examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This consolidates some examples to concentrate the reader on the important aspects and to reduce reading overhead. PR-URL: https://github.com/nodejs/node/pull/27044 Reviewed-By: Ben Noordhuis Reviewed-By: Rich Trott Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell Reviewed-By: Matteo Collina --- doc/api/fs.md | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 3917001d6c07c0..a4b7e81ecde301 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1588,19 +1588,15 @@ then the operation will fail. ```js const fs = require('fs'); +const { COPYFILE_EXCL } = fs.constants; -// destination.txt will be created or overwritten by default. -fs.copyFile('source.txt', 'destination.txt', (err) => { +function callback(err) { if (err) throw err; console.log('source.txt was copied to destination.txt'); -}); -``` - -If the third argument is a number, then it specifies `mode`: +} -```js -const fs = require('fs'); -const { COPYFILE_EXCL } = fs.constants; +// destination.txt will be created or overwritten by default. +fs.copyFile('source.txt', 'destination.txt', callback); // By using COPYFILE_EXCL, the operation will fail if destination.txt exists. fs.copyFile('source.txt', 'destination.txt', COPYFILE_EXCL, callback); @@ -1636,17 +1632,11 @@ then the operation will fail. ```js const fs = require('fs'); +const { COPYFILE_EXCL } = fs.constants; // destination.txt will be created or overwritten by default. fs.copyFileSync('source.txt', 'destination.txt'); console.log('source.txt was copied to destination.txt'); -``` - -If the third argument is a number, then it specifies `mode`: - -```js -const fs = require('fs'); -const { COPYFILE_EXCL } = fs.constants; // By using COPYFILE_EXCL, the operation will fail if destination.txt exists. fs.copyFileSync('source.txt', 'destination.txt', COPYFILE_EXCL); @@ -4718,20 +4708,17 @@ create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail. ```js -const fsPromises = require('fs').promises; +const { + promises: fsPromises, + constants: { + COPYFILE_EXCL + } +} = require('fs'); // destination.txt will be created or overwritten by default. fsPromises.copyFile('source.txt', 'destination.txt') .then(() => console.log('source.txt was copied to destination.txt')) .catch(() => console.log('The file could not be copied')); -``` - -If the third argument is a number, then it specifies `mode`: - -```js -const fs = require('fs'); -const fsPromises = fs.promises; -const { COPYFILE_EXCL } = fs.constants; // By using COPYFILE_EXCL, the operation will fail if destination.txt exists. fsPromises.copyFile('source.txt', 'destination.txt', COPYFILE_EXCL)