Skip to content

Commit

Permalink
Add a statSync to get the file mtime and set LastModified (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
stujo authored and MathieuLoutre committed May 20, 2017
1 parent d48d6d0 commit 29bf725
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,17 @@ S3Mock.prototype = {
return new FakeStream(search);
}
else {
fs.readFile(search.Bucket + '/' + search.Key, function (err, data) {
var path = search.Bucket + '/' + search.Key;
fs.readFile(path, function (err, data) {

var stat = fs.statSync(path);

if (!err) {
var props = {
Key: search.Key,
ETag: '"' + crypto.createHash('md5').update(data).digest('hex') + '"',
Body: data,
LastModified: stat.mtime,
ContentLength: data.length,
};

Expand Down Expand Up @@ -404,3 +408,4 @@ exports.config = config;
exports.S3 = function (options) {
return new S3Mock(options);
};

0 comments on commit 29bf725

Please sign in to comment.