From 49ace4b2fb822689c9ac13291f3acfc208c975e5 Mon Sep 17 00:00:00 2001 From: bcheidemann Date: Sat, 5 Jun 2021 18:05:19 +0100 Subject: [PATCH] docs: add documentation for the options in fs.readdir --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bd3ff3..8227a1d 100644 --- a/README.md +++ b/README.md @@ -849,7 +849,7 @@ fs.mkdtemp("/myDir/tmp", function (error, path) { }); ``` -#### fs.readdir(path, callback) +#### fs.readdir(path, [options], callback) Reads the contents of a directory. Asynchronous [readdir(3)](http://pubs.opengroup.org/onlinepubs/009695399/functions/readdir.html). Callback gets `(error, files)`, where `files` is an array containing the names of each directory entry (i.e., file, directory, link) in the directory, excluding `.` and `..`. @@ -870,6 +870,8 @@ fs.readdir('/docs', function(err, files) { }); ``` +Optionally accepts an options parameter, which can be either an encoding (e.g. "utf8") or an object with optional properties `encoding` and `withFileTypes`. The `encoding` property is a `string` which will determine the character encoding to use for the names of each directory entry. The `withFileTypes` property is a `boolean` which defaults to `false`. If `true`, this method will return an array of [fs.Dirent](https://nodejs.org/api/fs.html#fs_class_fs_dirent) objects. The `name` property on the [fs.Dirent](https://nodejs.org/api/fs.html#fs_class_fs_dirent) object will be encoded using the specified character encoding. + #### fs.close(fd, callback) Closes a file descriptor. Asynchronous [close(2)](http://pubs.opengroup.org/onlinepubs/009695399/functions/close.html).