-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
35 lines (30 loc) · 811 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
var fs = require('graceful-fs');
var map = require('map-stream');
module.exports = function (options) {
return map(function (file, cb) {
if (file.isNull()) { return cb(null, file); }
// opens file
fs.open(file.path, 'a', function (err, fd) {
if (err) {
cb(err, file);
return;
}
if (file.stat.atime && file.stat.mtime) {
// Update file modification and access time
fs.futimes(fd, file.stat.atime, file.stat.mtime, function (err) {
if (err) {
cb(err, file);
return;
}
fs.close(fd, function () {
cb(null, file);
});
});
} else {
// File may be not null, but has change name (map, etc)
cb(null, file);
}
});
});
}