|
2 | 2 |
|
3 | 3 | const { readFile, readFileSync, stat, statSync } = require('hexo-fs');
|
4 | 4 |
|
5 |
| -function File({ source, path, params, type }) { |
6 |
| - this.source = source; |
7 |
| - this.path = path; |
8 |
| - this.params = params; |
9 |
| - this.type = type; |
10 |
| -} |
11 |
| - |
12 |
| -File.prototype.read = function(options, callback) { |
13 |
| - return readFile(this.source, options).asCallback(callback); |
14 |
| -}; |
| 5 | +class File { |
| 6 | + constructor({ source, path, params, type }) { |
| 7 | + this.source = source; |
| 8 | + this.path = path; |
| 9 | + this.params = params; |
| 10 | + this.type = type; |
| 11 | + } |
15 | 12 |
|
16 |
| -File.prototype.readSync = function(options) { |
17 |
| - return readFileSync(this.source, options); |
18 |
| -}; |
| 13 | + read(options, callback) { |
| 14 | + return readFile(this.source, options).asCallback(callback); |
| 15 | + } |
19 | 16 |
|
20 |
| -File.prototype.stat = function(options, callback) { |
21 |
| - if (!callback && typeof options === 'function') { |
22 |
| - callback = options; |
23 |
| - options = {}; |
| 17 | + readSync(options) { |
| 18 | + return readFileSync(this.source, options); |
24 | 19 | }
|
25 | 20 |
|
26 |
| - return stat(this.source).asCallback(callback); |
27 |
| -}; |
| 21 | + stat(options, callback) { |
| 22 | + if (!callback && typeof options === 'function') { |
| 23 | + callback = options; |
| 24 | + options = {}; |
| 25 | + } |
28 | 26 |
|
29 |
| -File.prototype.statSync = function(options) { |
30 |
| - return statSync(this.source); |
31 |
| -}; |
| 27 | + return stat(this.source).asCallback(callback); |
| 28 | + } |
| 29 | + |
| 30 | + statSync(options) { |
| 31 | + return statSync(this.source); |
| 32 | + } |
| 33 | +} |
32 | 34 |
|
33 | 35 | File.TYPE_CREATE = 'create';
|
34 | 36 | File.TYPE_UPDATE = 'update';
|
|
0 commit comments