forked from nodejs/node-v0.x-archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles2buffer.js
More file actions
executable file
·37 lines (35 loc) · 812 Bytes
/
Copy pathfiles2buffer.js
File metadata and controls
executable file
·37 lines (35 loc) · 812 Bytes
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
#!/usr/local/bin/node
var fs=require('fs');
console.log('var data={};');
for (var f=2; f<process.argv.length;++f) {
var buf='';
var path=process.argv[f];
var content;
var ext=path.replace(/.*\.([^\.]+)$/,"$1").toLowerCase();
switch(ext) {
case 'types':
case 'txt':
case 'js':
case 'css':
case 'html':
case 'htm':
case 'txt':
case 'json':
encoding='utf8';
content=fs.readFileSync(path,encoding);
for (var i=0; i<content.length; ++i) {
buf+=(i?',':'')+content.charCodeAt(i);
}
break;
default:
encoding='binary';
content=fs.readFileSync(path,encoding);
for (var i=0; i<content.length; ++i) {
buf+=(i?',':'')+content.charCodeAt(i);
}
break;
}
var def='data["'+path+'"]=new Buffer(['+buf+'])';
console.log(def);
}
console.log('module.exports=data;');