From b531ac0ebc3d6c9a438c62dd4cddbe311cb9c522 Mon Sep 17 00:00:00 2001 From: dustinnewman98 Date: Sat, 17 Feb 2018 16:09:05 -0800 Subject: [PATCH 1/5] doc: improved documentation for fs.unlink() Refs: https://github.com/nodejs/node/issues/11135 --- doc/api/fs.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index a4a9e5fd3f2096..9bdcb2b47a6fbb 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2745,12 +2745,31 @@ changes: it will emit a deprecation warning. --> -* `path` {string|Buffer|URL} +* `path` {string|Buffer|URL} File name or file descriptor * `callback` {Function} * `err` {Error} -Asynchronous unlink(2). No arguments other than a possible exception are given -to the completion callback. +Asynchronously removes a file or symbolic link. No arguments other than a +possible exception are given to the completion callback. + +```js +// Assuming that 'path/file.txt' is a regular file. +fs.unlink('path/file.txt', (err) => { + if (err) throw err; + console.log('path/file.txt was deleted'); +}); +``` + +Note that unlink() will not work on a directory, empty or otherwise. + +```js +// Assuming that 'tmpDir' is a directory. +fs.unlink('tmpDir', (err) => { + // err is not null because a directory cannot be deleted through unlink(). +}); +``` + +See also: unlink(2) ## fs.unlinkSync(path) -* `path` {string|Buffer|URL} File name or file descriptor +* `path` {string|Buffer|URL} * `callback` {Function} * `err` {Error} @@ -2760,7 +2760,7 @@ fs.unlink('path/file.txt', (err) => { }); ``` -Note that unlink() will not work on a directory, empty or otherwise. +`fs.unlink()` will not work on a directory, empty or otherwise. ```js // Assuming that 'tmpDir' is a directory. From 82b486cb9407e5f00b0017466dbf780dc6ef7e61 Mon Sep 17 00:00:00 2001 From: dustinnewman98 Date: Sun, 18 Feb 2018 12:01:45 -0800 Subject: [PATCH 3/5] fixup! Added function to remove directory. --- doc/api/fs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 998566ea20f225..b0a2f0744bf1c7 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2760,7 +2760,7 @@ fs.unlink('path/file.txt', (err) => { }); ``` -`fs.unlink()` will not work on a directory, empty or otherwise. +`fs.unlink()` will not work on a directory, empty or otherwise. To remove a directory, use `fs.rmdir()`. ```js // Assuming that 'tmpDir' is a directory. From 8e2e47bf5ca1bd244bee82acce64e85c3709fc3f Mon Sep 17 00:00:00 2001 From: dustinnewman98 Date: Sun, 18 Feb 2018 12:27:58 -0800 Subject: [PATCH 4/5] fixup! Addressed concerns. --- doc/api/fs.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index b0a2f0744bf1c7..12305f1f158e7a 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2760,14 +2760,7 @@ fs.unlink('path/file.txt', (err) => { }); ``` -`fs.unlink()` will not work on a directory, empty or otherwise. To remove a directory, use `fs.rmdir()`. - -```js -// Assuming that 'tmpDir' is a directory. -fs.unlink('tmpDir', (err) => { - // err is not null because a directory cannot be deleted through unlink(). -}); -``` +`fs.unlink()` will not work on a directory, empty or otherwise. To remove a directory, use [`fs.rmdir()`][]. See also: unlink(2) @@ -4491,6 +4484,7 @@ The following constants are meant for use with the [`fs.Stats`][] object's [`fs.read()`]: #fs_fs_read_fd_buffer_offset_length_position_callback [`fs.readFile()`]: #fs_fs_readfile_path_options_callback [`fs.readFileSync()`]: #fs_fs_readfilesync_path_options +[`fs.rmdir()`]: #fs_fs_rmdir_path_callback [`fs.stat()`]: #fs_fs_stat_path_callback [`fs.utimes()`]: #fs_fs_utimes_path_atime_mtime_callback [`fs.watch()`]: #fs_fs_watch_filename_options_listener From 55f37ae0dc91bf32d88013eeb91df6735af1cd8e Mon Sep 17 00:00:00 2001 From: dustinnewman98 Date: Sun, 18 Feb 2018 12:33:22 -0800 Subject: [PATCH 5/5] fixup! wrapped at 80 characters --- doc/api/fs.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index 12305f1f158e7a..ae559d0ecff744 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -2760,7 +2760,8 @@ fs.unlink('path/file.txt', (err) => { }); ``` -`fs.unlink()` will not work on a directory, empty or otherwise. To remove a directory, use [`fs.rmdir()`][]. +`fs.unlink()` will not work on a directory, empty or otherwise. To remove a +directory, use [`fs.rmdir()`][]. See also: unlink(2)