| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e2279e2 commit 9dda771
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -218,7 +218,7 @@ For a regular file [`util.inspect(stats)`][] would return a string very | |||
| 218 | 218 | similar to this: | |
| 219 | 219 | ||
| 220 | 220 | ```js | |
| 221 | - { | ||
| 221 | + Stats { | ||
| 222 | 222 | dev: 2114, | |
| 223 | 223 | ino: 48064969, | |
| 224 | 224 | mode: 33188, | |
@@ -232,8 +232,7 @@ similar to this: | |||
| 232 | 232 | atime: Mon, 10 Oct 2011 23:24:11 GMT, | |
| 233 | 233 | mtime: Mon, 10 Oct 2011 23:24:11 GMT, | |
| 234 | 234 | ctime: Mon, 10 Oct 2011 23:24:11 GMT, | |
| 235 | - birthtime: Mon, 10 Oct 2011 23:24:11 GMT | ||
| 236 | - } | ||
| 235 | + birthtime: Mon, 10 Oct 2011 23:24:11 GMT } | ||
| 237 | 236 | ``` | |
| 238 | 237 | ||
| 239 | 238 | Please note that `atime`, `mtime`, `birthtime`, and `ctime` are | |
@@ -377,12 +376,12 @@ fs.access('myfile', (err) => { | |||
| 377 | 376 | ```js | |
| 378 | 377 | fs.open('myfile', 'wx', (err, fd) => { | |
| 379 | 378 | if (err) { | |
| 380 | - if (err.code === "EEXIST") { | ||
| 379 | + if (err.code === 'EEXIST') { | ||
| 381 | 380 | console.error('myfile already exists'); | |
| 382 | 381 | return; | |
| 383 | - } else { | ||
| 384 | - throw err; | ||
| 385 | 382 | } | |
| 383 | + | ||
| 384 | + throw err; | ||
| 386 | 385 | } | |
| 387 | 386 | ||
| 388 | 387 | writeMyData(fd); | |
@@ -394,12 +393,12 @@ fs.open('myfile', 'wx', (err, fd) => { | |||
| 394 | 393 | ```js | |
| 395 | 394 | fs.access('myfile', (err) => { | |
| 396 | 395 | if (err) { | |
| 397 | - if (err.code === "ENOENT") { | ||
| 396 | + if (err.code === 'ENOENT') { | ||
| 398 | 397 | console.error('myfile does not exist'); | |
| 399 | 398 | return; | |
| 400 | - } else { | ||
| 401 | - throw err; | ||
| 402 | 399 | } | |
| 400 | + | ||
| 401 | + throw err; | ||
| 403 | 402 | } | |
| 404 | 403 | ||
| 405 | 404 | fs.open('myfile', 'r', (err, fd) => { | |
@@ -414,12 +413,12 @@ fs.access('myfile', (err) => { | |||
| 414 | 413 | ```js | |
| 415 | 414 | fs.open('myfile', 'r', (err, fd) => { | |
| 416 | 415 | if (err) { | |
| 417 | - if (err.code === "ENOENT") { | ||
| 416 | + if (err.code === 'ENOENT') { | ||
| 418 | 417 | console.error('myfile does not exist'); | |
| 419 | 418 | return; | |
| 420 | - } else { | ||
| 421 | - throw err; | ||
| 422 | 419 | } | |
| 420 | + | ||
| 421 | + throw err; | ||
| 423 | 422 | } | |
| 424 | 423 | ||
| 425 | 424 | readMyData(fd); | |
@@ -729,13 +728,14 @@ fs.exists('myfile', (exists) => { | |||
| 729 | 728 | ```js | |
| 730 | 729 | fs.open('myfile', 'wx', (err, fd) => { | |
| 731 | 730 | if (err) { | |
| 732 | - if (err.code === "EEXIST") { | ||
| 731 | + if (err.code === 'EEXIST') { | ||
| 733 | 732 | console.error('myfile already exists'); | |
| 734 | 733 | return; | |
| 735 | - } else { | ||
| 736 | - throw err; | ||
| 737 | 734 | } | |
| 735 | + | ||
| 736 | + throw err; | ||
| 738 | 737 | } | |
| 738 | + | ||
| 739 | 739 | writeMyData(fd); | |
| 740 | 740 | }); | |
| 741 | 741 | ``` | |
@@ -759,15 +759,15 @@ fs.exists('myfile', (exists) => { | |||
| 759 | 759 | ```js | |
| 760 | 760 | fs.open('myfile', 'r', (err, fd) => { | |
| 761 | 761 | if (err) { | |
| 762 | - if (err.code === "ENOENT") { | ||
| 762 | + if (err.code === 'ENOENT') { | ||
| 763 | 763 | console.error('myfile does not exist'); | |
| 764 | 764 | return; | |
| 765 | - } else { | ||
| 766 | - throw err; | ||
| 767 | 765 | } | |
| 768 | - } else { | ||
| 769 | - readMyData(fd); | ||
| 766 | + | ||
| 767 | + throw err; | ||
| 770 | 768 | } | |
| 769 | + | ||
| 770 | + readMyData(fd); | ||
| 771 | 771 | }); | |
| 772 | 772 | ``` | |
| 773 | 773 | ||
@@ -945,7 +945,7 @@ const fd = fs.openSync('temp.txt', 'r+'); | |||
| 945 | 945 | ||
| 946 | 946 | // truncate the file to 10 bytes, whereas the actual size is 7 bytes | |
| 947 | 947 | fs.ftruncate(fd, 10, (err) => { | |
| 948 | - assert.ifError(!err); | ||
| 948 | + assert.ifError(err); | ||
| 949 | 949 | console.log(fs.readFileSync('temp.txt')); | |
| 950 | 950 | }); | |
| 951 | 951 | // Prints: <Buffer 4e 6f 64 65 2e 6a 73 00 00 00> | |
@@ -1154,8 +1154,8 @@ fs.mkdtemp(tmpDir, (err, folder) => { | |||
| 1154 | 1154 | }); | |
| 1155 | 1155 | ||
| 1156 | 1156 | // This method is *CORRECT*: | |
| 1157 | - const path = require('path'); | ||
| 1158 | - fs.mkdtemp(tmpDir + path.sep, (err, folder) => { | ||
| 1157 | + const { sep } = require('path'); | ||
| 1158 | + fs.mkdtemp(`${tmpDir}${sep}`, (err, folder) => { | ||
| 1159 | 1159 | if (err) throw err; | |
| 1160 | 1160 | console.log(folder); | |
| 1161 | 1161 | // Will print something similar to `/tmp/abc123`. | |
@@ -1564,7 +1564,7 @@ argument will automatically be normalized to absolute path. | |||
| 1564 | 1564 | Here is an example below: | |
| 1565 | 1565 | ||
| 1566 | 1566 | ```js | |
| 1567 | - fs.symlink('./foo', './new-port'); | ||
| 1567 | + fs.symlink('./foo', './new-port', callback); | ||
| 1568 | 1568 | ``` | |
| 1569 | 1569 | ||
| 1570 | 1570 | It creates a symbolic link named "new-port" that points to "foo". | |
@@ -1910,7 +1910,7 @@ Example: | |||
| 1910 | 1910 | ```js | |
| 1911 | 1911 | fs.writeFile('message.txt', 'Hello Node.js', (err) => { | |
| 1912 | 1912 | if (err) throw err; | |
| 1913 | - console.log('It\'s saved!'); | ||
| 1913 | + console.log('The file has been saved!'); | ||
| 1914 | 1914 | }); | |
| 1915 | 1915 | ``` | |
| 1916 | 1916 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments