@@ -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);
@@ -779,13 +778,14 @@ fs.exists('myfile', (exists) => {
779
778
``` js
780
779
fs .open (' myfile' , ' wx' , (err , fd ) => {
781
780
if (err) {
782
- if (err .code === " EEXIST" ) {
781
+ if (err .code === ' EEXIST' ) {
783
782
console .error (' myfile already exists' );
784
783
return ;
785
- } else {
786
- throw err;
787
784
}
785
+
786
+ throw err;
788
787
}
788
+
789
789
writeMyData (fd);
790
790
});
791
791
```
@@ -809,15 +809,15 @@ fs.exists('myfile', (exists) => {
809
809
``` js
810
810
fs .open (' myfile' , ' r' , (err , fd ) => {
811
811
if (err) {
812
- if (err .code === " ENOENT" ) {
812
+ if (err .code === ' ENOENT' ) {
813
813
console .error (' myfile does not exist' );
814
814
return ;
815
- } else {
816
- throw err;
817
815
}
818
- } else {
819
- readMyData (fd) ;
816
+
817
+ throw err ;
820
818
}
819
+
820
+ readMyData (fd);
821
821
});
822
822
```
823
823
@@ -1025,7 +1025,7 @@ const fd = fs.openSync('temp.txt', 'r+');
1025
1025
1026
1026
// truncate the file to 10 bytes, whereas the actual size is 7 bytes
1027
1027
fs .ftruncate (fd, 10 , (err ) => {
1028
- assert .ifError (! err);
1028
+ assert .ifError (err);
1029
1029
console .log (fs .readFileSync (' temp.txt' ));
1030
1030
});
1031
1031
// Prints: <Buffer 4e 6f 64 65 2e 6a 73 00 00 00>
@@ -1281,8 +1281,8 @@ fs.mkdtemp(tmpDir, (err, folder) => {
1281
1281
});
1282
1282
1283
1283
// This method is *CORRECT*:
1284
- const path = require (' path' );
1285
- fs .mkdtemp (tmpDir + path . sep , (err , folder ) => {
1284
+ const { sep } = require (' path' );
1285
+ fs .mkdtemp (` ${ tmpDir}${ sep} ` , (err , folder ) => {
1286
1286
if (err) throw err;
1287
1287
console .log (folder);
1288
1288
// Will print something similar to `/tmp/abc123`.
@@ -1763,7 +1763,7 @@ argument will automatically be normalized to absolute path.
1763
1763
Here is an example below:
1764
1764
1765
1765
``` js
1766
- fs .symlink (' ./foo' , ' ./new-port' );
1766
+ fs .symlink (' ./foo' , ' ./new-port' , callback );
1767
1767
```
1768
1768
1769
1769
It creates a symbolic link named "new-port" that points to "foo".
@@ -2174,7 +2174,7 @@ Example:
2174
2174
``` js
2175
2175
fs .writeFile (' message.txt' , ' Hello Node.js' , (err ) => {
2176
2176
if (err) throw err;
2177
- console .log (' It \' s saved!' );
2177
+ console .log (' The file has been saved!' );
2178
2178
});
2179
2179
```
2180
2180
0 commit comments