add createdDate, sha1

This commit is contained in:
AJ ONeal 2015-01-10 12:43:25 -07:00
parent c753a66794
commit bac3b49985
1 changed files with 34 additions and 14 deletions

View File

@ -18,6 +18,9 @@ function strip(prefix, pathname) {
function walkDir(parent, sub, opts) {
opts = opts || {};
if (false !== opts.sha1sum) {
opts.sha1sum = true;
}
var prefix = path.resolve(parent)
, trueRoot = path.resolve(prefix, sub)
@ -58,6 +61,8 @@ function walkDir(parent, sub, opts) {
files.push({
name: stat.name
, relativePath: strip(prefix, filepath)
, path: path.join(strip(prefix, filepath), stat.name)
, type: undefined
, error: stat.error
});
@ -81,24 +86,33 @@ function walkDir(parent, sub, opts) {
file = {
name: stat.name
, lastModifiedDate: stat.mtime.toISOString()
, size: stat.size
, relativePath: dirname
, path: path.join(dirname, stat.name)
, createdDate: (stat.birthtime||stat.ctime).toISOString()
, lastModifiedDate: stat.mtime.toISOString()
, size: stat.size
, type: undefined // TODO include mimetype
};
files.push(file);
if (opts.contents) {
if (!(opts.sha1sum || opts.content)) {
return;
}
// TODO stream sha1 (for assets)
return fs.readFileAsync(path.join(root, stat.name), null).then(function (buffer) {
var contents = buffer.toString('utf8')
;
file.contents = contents;
file.sha1 = sha1sum(contents);
file.size = buffer.length;
file.type = undefined;
});
if (opts.contents) {
file.contents = contents;
}
});
}
if (!opts.contents) {
@ -141,11 +155,17 @@ function getfs(blogdir, filepaths) {
return fs.lstatAsync(pathname).then(function (stat) {
return fs.readFileAsync(pathname, null).then(function (buffer) {
files.push({
path: filepath
, size: buffer.length
name: path.basename(pathname)
, relativePath: path.dirname(filepath)
, path: filepath
, createdDate: (stat.birthtime||stat.ctime).toISOString()
, lastModifiedDate: stat.mtime.toISOString()
, contents: buffer.toString('utf8')
, size: buffer.length
, sha1: sha1sum(buffer)
, type: undefined
});