summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorVse Mozhet Byt <vsemozhetbyt@gmail.com>2017-03-25 15:33:03 +0200
committerMyles Borins <mylesborins@google.com>2017-04-18 20:02:21 -0400
commit9dda771c1f6c67f1f7bcca1f8edad7ec9c959459 (patch)
tree649939f87001f9c255aa89181ae408642f13fd0f /doc
parente2279e297ae56bfb6a849ed9199b33e2b72d32ba (diff)
downloadnode-new-9dda771c1f6c67f1f7bcca1f8edad7ec9c959459.tar.gz
doc: update and modernize examples in fs.ms
* unify quotes in fs.md * avoid quote escaping in fs.md * simplify logics in fs.md * concatenation -> template literal in fs.md * add missing callback in fs.md * fix typo in fs.md * update output example in fs.md PR-URL: https://github.com/nodejs/node/pull/12035 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/fs.md50
1 files changed, 25 insertions, 25 deletions
diff --git a/doc/api/fs.md b/doc/api/fs.md
index 5471c5f5e6..36a653386d 100644
--- a/doc/api/fs.md
+++ b/doc/api/fs.md
@@ -218,7 +218,7 @@ For a regular file [`util.inspect(stats)`][] would return a string very
similar to this:
```js
-{
+Stats {
dev: 2114,
ino: 48064969,
mode: 33188,
@@ -232,8 +232,7 @@ similar to this:
atime: Mon, 10 Oct 2011 23:24:11 GMT,
mtime: Mon, 10 Oct 2011 23:24:11 GMT,
ctime: Mon, 10 Oct 2011 23:24:11 GMT,
- birthtime: Mon, 10 Oct 2011 23:24:11 GMT
-}
+ birthtime: Mon, 10 Oct 2011 23:24:11 GMT }
```
Please note that `atime`, `mtime`, `birthtime`, and `ctime` are
@@ -377,12 +376,12 @@ fs.access('myfile', (err) => {
```js
fs.open('myfile', 'wx', (err, fd) => {
if (err) {
- if (err.code === "EEXIST") {
+ if (err.code === 'EEXIST') {
console.error('myfile already exists');
return;
- } else {
- throw err;
}
+
+ throw err;
}
writeMyData(fd);
@@ -394,12 +393,12 @@ fs.open('myfile', 'wx', (err, fd) => {
```js
fs.access('myfile', (err) => {
if (err) {
- if (err.code === "ENOENT") {
+ if (err.code === 'ENOENT') {
console.error('myfile does not exist');
return;
- } else {
- throw err;
}
+
+ throw err;
}
fs.open('myfile', 'r', (err, fd) => {
@@ -414,12 +413,12 @@ fs.access('myfile', (err) => {
```js
fs.open('myfile', 'r', (err, fd) => {
if (err) {
- if (err.code === "ENOENT") {
+ if (err.code === 'ENOENT') {
console.error('myfile does not exist');
return;
- } else {
- throw err;
}
+
+ throw err;
}
readMyData(fd);
@@ -729,13 +728,14 @@ fs.exists('myfile', (exists) => {
```js
fs.open('myfile', 'wx', (err, fd) => {
if (err) {
- if (err.code === "EEXIST") {
+ if (err.code === 'EEXIST') {
console.error('myfile already exists');
return;
- } else {
- throw err;
}
+
+ throw err;
}
+
writeMyData(fd);
});
```
@@ -759,15 +759,15 @@ fs.exists('myfile', (exists) => {
```js
fs.open('myfile', 'r', (err, fd) => {
if (err) {
- if (err.code === "ENOENT") {
+ if (err.code === 'ENOENT') {
console.error('myfile does not exist');
return;
- } else {
- throw err;
}
- } else {
- readMyData(fd);
+
+ throw err;
}
+
+ readMyData(fd);
});
```
@@ -945,7 +945,7 @@ const fd = fs.openSync('temp.txt', 'r+');
// truncate the file to 10 bytes, whereas the actual size is 7 bytes
fs.ftruncate(fd, 10, (err) => {
- assert.ifError(!err);
+ assert.ifError(err);
console.log(fs.readFileSync('temp.txt'));
});
// Prints: <Buffer 4e 6f 64 65 2e 6a 73 00 00 00>
@@ -1154,8 +1154,8 @@ fs.mkdtemp(tmpDir, (err, folder) => {
});
// This method is *CORRECT*:
-const path = require('path');
-fs.mkdtemp(tmpDir + path.sep, (err, folder) => {
+const { sep } = require('path');
+fs.mkdtemp(`${tmpDir}${sep}`, (err, folder) => {
if (err) throw err;
console.log(folder);
// Will print something similar to `/tmp/abc123`.
@@ -1564,7 +1564,7 @@ argument will automatically be normalized to absolute path.
Here is an example below:
```js
-fs.symlink('./foo', './new-port');
+fs.symlink('./foo', './new-port', callback);
```
It creates a symbolic link named "new-port" that points to "foo".
@@ -1910,7 +1910,7 @@ Example:
```js
fs.writeFile('message.txt', 'Hello Node.js', (err) => {
if (err) throw err;
- console.log('It\'s saved!');
+ console.log('The file has been saved!');
});
```