-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
60 lines (57 loc) · 1.55 KB
/
index.js
File metadata and controls
60 lines (57 loc) · 1.55 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
/* .#.
@@@@@
@@@@@
@
.....@@@
.@@@@@@@
@@@@@@@
@@@@@@@:@@@..@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@ @@@@
.@@@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@
'@@@@@@@@@@@@@@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@ @@@
:@@@@@@@@@: @@@@@@@@ @@@ @@@ @@@@@@@@@ @@@@@@@@@ @@@ @@@
`@@@@: @@@ @@@ @@@ @@@#@@@ @@@@@@@@ @@@@@@@@@@
@@@ @@@@@@@@@ @@@@@@@@' @@@ @@@ @@@ @@@ @@@
+##` @@@@@@@@ @@@@@ @@@ @@@ @@@ @@@ @@@
Supra
NodeJS
Developer
Friendly
Framework.
File Class File
*/
var exts = require('./exts.js')
module.exports = Supra.Class.extend({
/**
* File Class contructor
* @param {String} path File path
* @param {Object} res HTTP response
* @param {Function} callback Will be called if the file exists fail.
* @return {Object} File Class
*/
init : function(path,res,callback){
this.res = res;
this.path = path;
Supra.fs.exists(this.path, function (exists) {
if (exists){
this.send();
}else{
callback();
}
}.bind(this));
return this;
},
/**
* Sends the file over HTTP response
* @return {Object} File Class
*/
send : function(){
var stat = Supra.fs.statSync(this.path);
var readStream = Supra.fs.createReadStream(this.path);
this.res.writeHead(200,{
'Content-Type' : exts(this.path),
'Content-Length' : stat.size,
})
readStream.pipe(this.res);
return this;
}
})