| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -301,10 +301,14 @@ argument to `fs.createReadStream()`. If `path` is passed as a string, then | |||
| 301 | 301 | ## Class: fs.Stats | |
| 302 | 302 | <!-- YAML | |
| 303 | 303 | added: v0.1.21 | |
| 304 | + changes: | ||
| 305 | + - version: REPLACEME | ||
| 306 | + pr-url: https://github.com/nodejs/node/pull/13173 | ||
| 307 | + description: Added times as numbers. | ||
| 304 | 308 | --> | |
| 305 | 309 | ||
| 306 | - Objects returned from [`fs.stat()`][], [`fs.lstat()`][] and [`fs.fstat()`][] and their | ||
| 307 | - synchronous counterparts are of this type. | ||
| 310 | + Objects returned from [`fs.stat()`][], [`fs.lstat()`][] and [`fs.fstat()`][] and | ||
| 311 | + their synchronous counterparts are of this type. | ||
| 308 | 312 | ||
| 309 | 313 | - `stats.isFile()` | |
| 310 | 314 | - `stats.isDirectory()` | |
@@ -329,20 +333,23 @@ Stats { | |||
| 329 | 333 | size: 527, | |
| 330 | 334 | blksize: 4096, | |
| 331 | 335 | blocks: 8, | |
| 336 | + atimeMs: 1318289051000.1, | ||
| 337 | + mtimeMs: 1318289051000.1, | ||
| 338 | + ctimeMs: 1318289051000.1, | ||
| 339 | + birthtimeMs: 1318289051000.1, | ||
| 332 | 340 | atime: Mon, 10 Oct 2011 23:24:11 GMT, | |
| 333 | 341 | mtime: Mon, 10 Oct 2011 23:24:11 GMT, | |
| 334 | 342 | ctime: Mon, 10 Oct 2011 23:24:11 GMT, | |
| 335 | 343 | birthtime: Mon, 10 Oct 2011 23:24:11 GMT } | |
| 336 | 344 | ``` | |
| 337 | 345 | ||
| 338 | - Please note that `atime`, `mtime`, `birthtime`, and `ctime` are | ||
| 339 | - instances of [`Date`][MDN-Date] object and appropriate methods should be used | ||
| 340 | - to compare the values of these objects. For most general uses | ||
| 341 | - [`getTime()`][MDN-Date-getTime] will return the number of milliseconds elapsed | ||
| 342 | - since _1 January 1970 00:00:00 UTC_ and this integer should be sufficient for | ||
| 343 | - any comparison, however there are additional methods which can be used for | ||
| 344 | - displaying fuzzy information. More details can be found in the | ||
| 345 | - [MDN JavaScript Reference][MDN-Date] page. | ||
| 346 | + *Note*: `atimeMs`, `mtimeMs`, `ctimeMs`, `birthtimeMs` are [numbers][MDN-Number] | ||
| 347 | + that hold the corresponding times in milliseconds. Their precision is platform | ||
| 348 | + specific. `atime`, `mtime`, `ctime`, and `birthtime` are [`Date`][MDN-Date] | ||
| 349 | + object alternate representations of the various times. The `Date` and number | ||
| 350 | + values are not connected. Assigning a new number value, or mutating the `Date` | ||
| 351 | + value, will not be reflected in the corresponding alternate representation. | ||
| 352 | + | ||
| 346 | 353 | ||
| 347 | 354 | ### Stat Time Values | |
| 348 | 355 | ||
@@ -2841,6 +2848,7 @@ The following constants are meant for use with the [`fs.Stats`][] object's | |||
| 2841 | 2848 | [FS Constants]: #fs_fs_constants_1 | |
| 2842 | 2849 | [MDN-Date-getTime]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getTime | |
| 2843 | 2850 | [MDN-Date]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date | |
| 2851 | + [MDN-Number]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type | ||
| 2844 | 2852 | [MSDN-Rel-Path]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx#fully_qualified_vs._relative_paths | |
| 2845 | 2853 | [Readable Stream]: stream.html#stream_class_stream_readable | |
| 2846 | 2854 | [Writable Stream]: stream.html#stream_class_stream_writable | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -196,6 +196,10 @@ function Stats( | |||
| 196 | 196 | this.ino = ino; | |
| 197 | 197 | this.size = size; | |
| 198 | 198 | this.blocks = blocks; | |
| 199 | + this.atimeMs = atim_msec; | ||
| 200 | + this.mtimeMs = mtim_msec; | ||
| 201 | + this.ctimeMs = ctim_msec; | ||
| 202 | + this.birthtimeMs = birthtim_msec; | ||
| 199 | 203 | this.atime = new Date(atim_msec + 0.5); | |
| 200 | 204 | this.mtime = new Date(mtim_msec + 0.5); | |
| 201 | 205 | this.ctime = new Date(ctim_msec + 0.5); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,38 +65,55 @@ fs.open('.', 'r', undefined, common.mustCall(function(err, fd) { | |||
| 65 | 65 | assert.fail(err); | |
| 66 | 66 | } | |
| 67 | 67 | if (stats) { | |
| 68 | - console.dir(stats); | ||
| 69 | 68 | assert.ok(stats.mtime instanceof Date); | |
| 70 | 69 | } | |
| 71 | 70 | fs.close(fd, assert.ifError); | |
| 72 | 71 | })); | |
| 73 | 72 | ||
| 74 | - console.log(`stating: ${__filename}`); | ||
| 75 | 73 | fs.stat(__filename, common.mustCall(function(err, s) { | |
| 76 | 74 | assert.ifError(err); | |
| 77 | - | ||
| 78 | - console.dir(s); | ||
| 79 | - | ||
| 80 | - console.log(`isDirectory: ${JSON.stringify(s.isDirectory())}`); | ||
| 81 | 75 | assert.strictEqual(false, s.isDirectory()); | |
| 82 | - | ||
| 83 | - console.log(`isFile: ${JSON.stringify(s.isFile())}`); | ||
| 84 | 76 | assert.strictEqual(true, s.isFile()); | |
| 85 | - | ||
| 86 | - console.log(`isSocket: ${JSON.stringify(s.isSocket())}`); | ||
| 87 | 77 | assert.strictEqual(false, s.isSocket()); | |
| 88 | - | ||
| 89 | - console.log(`isBlockDevice: ${JSON.stringify(s.isBlockDevice())}`); | ||
| 90 | 78 | assert.strictEqual(false, s.isBlockDevice()); | |
| 91 | - | ||
| 92 | - console.log(`isCharacterDevice: ${JSON.stringify(s.isCharacterDevice())}`); | ||
| 93 | 79 | assert.strictEqual(false, s.isCharacterDevice()); | |
| 94 | - | ||
| 95 | - console.log(`isFIFO: ${JSON.stringify(s.isFIFO())}`); | ||
| 96 | 80 | assert.strictEqual(false, s.isFIFO()); | |
| 97 | - | ||
| 98 | - console.log(`isSymbolicLink: ${JSON.stringify(s.isSymbolicLink())}`); | ||
| 99 | 81 | assert.strictEqual(false, s.isSymbolicLink()); | |
| 100 | - | ||
| 101 | - assert.ok(s.mtime instanceof Date); | ||
| 82 | + const keys = [ | ||
| 83 | + 'dev', 'mode', 'nlink', 'uid', | ||
| 84 | + 'gid', 'rdev', 'ino', 'size', | ||
| 85 | + 'atime', 'mtime', 'ctime', 'birthtime', | ||
| 86 | + 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs' | ||
| 87 | + ]; | ||
| 88 | + if (!common.isWindows) { | ||
| 89 | + keys.push('blocks', 'blksize'); | ||
| 90 | + } | ||
| 91 | + const numberFields = [ | ||
| 92 | + 'dev', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'ino', 'size', | ||
| 93 | + 'atimeMs', 'mtimeMs', 'ctimeMs', 'birthtimeMs' | ||
| 94 | + ]; | ||
| 95 | + const dateFields = ['atime', 'mtime', 'ctime', 'birthtime']; | ||
| 96 | + keys.forEach(function(k) { | ||
| 97 | + assert.ok(k in s, `${k} should be in Stats`); | ||
| 98 | + assert.notStrictEqual(s[k], undefined, `${k} should not be undefined`); | ||
| 99 | + assert.notStrictEqual(s[k], null, `${k} should not be null`); | ||
| 100 | + }); | ||
| 101 | + numberFields.forEach((k) => { | ||
| 102 | + assert.strictEqual(typeof s[k], 'number', `${k} should be a number`); | ||
| 103 | + }); | ||
| 104 | + dateFields.forEach((k) => { | ||
| 105 | + assert.ok(s[k] instanceof Date, `${k} should be a Date`); | ||
| 106 | + }); | ||
| 107 | + const jsonString = JSON.stringify(s); | ||
| 108 | + const parsed = JSON.parse(jsonString); | ||
| 109 | + keys.forEach(function(k) { | ||
| 110 | + assert.notStrictEqual(parsed[k], undefined, `${k} should not be undefined`); | ||
| 111 | + assert.notStrictEqual(parsed[k], null, `${k} should not be null`); | ||
| 112 | + }); | ||
| 113 | + numberFields.forEach((k) => { | ||
| 114 | + assert.strictEqual(typeof parsed[k], 'number', `${k} should be a number`); | ||
| 115 | + }); | ||
| 116 | + dateFields.forEach((k) => { | ||
| 117 | + assert.strictEqual(typeof parsed[k], 'string', `${k} should be a string`); | ||
| 118 | + }); | ||
| 102 | 119 | })); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments