-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslips.txt
132 lines (121 loc) · 3.73 KB
/
slips.txt
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
slip 6a
const http=require('http');
const fs=require('fs');
const formidable = require('formidable');
const server=http.createServer(function(req,res){
if(req.url=='/'){
res.writeHead(200,{"content-type":"text/html"})
res.write('<form action="fapp" method="post" enctype="multipart/form-data">')
res.write('<h1> select two files</h1><br/>')
res.write('<input type="file" name="rf"></input>')
res.write('<input type="submit"></input>')
res.end();
}else if (req.url=='/fapp') {
var form = new formidable.IncomingForm();
form.parse(req, (err, fields, files) => {
if (err) {
res.write(err)
}
fs.readFile(files.rf.name,"utf8",(err,data)=>{
res.writeHead(200,{"content-type":"text/html"});
if (err)throw err;
res.write(data);
res.end()
})
})
}
else {
res.end("page not found")
}
}).listen(3000,()=>console.log("server created sucessfully"));
slip 7a:
const http = require('http');
const fs = require('fs');
const formidable = require('formidable');
http.createServer((req, res) => {
if (req.url == '/') {
res.writeHead(200, {
'content-type': 'text/html'
})
res.write('<form action="fapp" method="post" enctype="multipart/form-data">')
res.write('<h1> select two files</h1><br/>')
res.write('<input type="file" name="rf"></input>')
res.write('<input type="file" name="wf"></input>')
res.write('<input type="submit"></input>')
res.end();
console.log("done with sending form ");
} else if (req.url == '/fapp') {
var form = new formidable.IncomingForm();
form.parse(req, (err, fields, files) => {
if (err) {
res.write(err)
}
var w = fs.createWriteStream(files.wf.name, {
flags: 'a'
})
var r = fs.createReadStream(files.rf.name)
w.on('close', () => {
console.log("done writing");
})
r.pipe(w)
res.end("sucess")
})
} else {
res.end("page not file");
}
}).listen(8080, () => console.log("started"))
slip 8:
const http = require('http');
const fs = require('fs');
const formidable = require('formidable');
const {Transform} = require('stream');
// create a server
http.createServer((req,res) => {
if(req.url=="/"){
res.writeHead(200,{"content-type":"text/html"})
res.write('<form action="fapp" method="post" enctype="multipart/form-data">')
res.write('<h1> select two files</h1><br/>')
res.write('<input type="file" name="rf"></input>')
res.write('<input type="file" name="wf"></input>')
res.write('<input type="file" name="mf"></input>')
res.write('<input type="submit"></input>')
res.end();
}
else if (req.url=='/fapp') {
var form= new formidable.IncomingForm();
form.parse(req,(err,fields,files) => {
if(err){
res.write(err)
}
const uppercase = new Transform({
transform :(chunk,encoding,done )=>{
const result = chunk.toString().toUpperCase()
console.log(result);
done(null,result)
}
})
var r = fs.createReadStream(files.rf.name);
var r1 = fs.createReadStream(files.wf.name);
var w=fs.createWriteStream(files.mf.name,{flags:'w'});
w.on('close',() => {
console.log("writing done");
})
r.pipe(uppercase).pipe(w)
r1.pipe(uppercase).pipe(w)
res.end("sucessfull")
})
}else {
res.end("page not found")
}
}).listen(3000,() => {
console.log("server started at 3000");
})
slip 14a:
var fs=require("fs")
let file=fs.readFileSync(__dirname+"/timeout.js","utf8");
if(file.indexOf("z")>=0){
console.log("wrold is present");
}
else{
console.log("world is not present");
}