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