mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add FileApi File
This commit is contained in:
parent
f754406d20
commit
eb308bd364
1 changed files with 44 additions and 0 deletions
44
helpers/scanner/file-api.js
Normal file
44
helpers/scanner/file-api.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
export function File (input) {
|
||||
var self = this;
|
||||
|
||||
function updateStat(stat) {
|
||||
self.stat = stat;
|
||||
self.lastModifiedDate = self.stat.mtime;
|
||||
self.size = self.stat.size;
|
||||
}
|
||||
|
||||
if ('string' === typeof input) {
|
||||
self.path = input;
|
||||
} else {
|
||||
Object.keys(input).forEach(function (k) {
|
||||
self[k] = input[k];
|
||||
});
|
||||
}
|
||||
|
||||
self.name = self.name// || path.basename(self.path||'');
|
||||
if (!self.name) {
|
||||
throw new Error("No name");
|
||||
}
|
||||
self.type = self.type// || mime.lookup(self.name);
|
||||
|
||||
if (!self.path) {
|
||||
if (self.buffer) {
|
||||
self.size = self.buffer.length;
|
||||
} else if (!self.stream) {
|
||||
throw new Error('No input, nor stream, nor buffer.');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self.jsdom) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!self.async) {
|
||||
// updateStat(fs.statSync(self.path));
|
||||
// } else {
|
||||
// fs.stat(self.path, function (err, stat) {
|
||||
// updateStat(stat);
|
||||
// });
|
||||
// }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue