Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFile.js
More file actions
Latest commit
62 lines (53 loc) · 1.22 KB
/
Copy pathFile.js
File metadata and controls
62 lines (53 loc) · 1.22 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// File
//
// http://www.w3.org/TR/FileAPI/#dfn-file
// https://developer.mozilla.org/en/DOM/File
(function(){
"use strict";
varfs=require("fs"),
path=require("path"),
mime=require("mime");
// string
// stream
// buffer
functionFile(input){
varself=this;
functionupdateStat(stat){
self.stat=stat;
self.lastModifiedDate=self.stat.mtime;
self.size=self.stat.size;
}
if('string'===typeofinput){
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){
thrownewError("No name");
}
self.type=self.type||mime.lookup(self.name);
if(!self.path){
if(self.buffer){
self.size=self.buffer.length;
}elseif(!self.stream){
thrownewError('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);
});
}
}
module.exports=File;
}());