https://www.cnblogs.com/lalalagq/p/9749680.html
sf.readFile('www${pathname}',(err,buffer)=>{
res.write(buffer);
});
.占用内存;
.资源使用不均匀
const fs = require('fs);
let rs = fs.createReadStream('1.txt');
let ws = fs.createWriteStream('2.txt');
rs.pipe(ws);
rs.on('error',()=>){
console.log(err);
})
ws.on('finish',()=>{
console.log('完成');
})
Comedy:
读写流——压缩、加密
数据库不能直接接受流
const fs = require('fs);
const zilib = require('zlib');
let rs = fs.createReadStream('1.txt');
let gz = zlib.createGzip();
let ws = fs.createWriteStream('2.txt.gz');
rs.pipe(gz).pipe(ws);
rs.on('error',()=>){
console.log(err);
})
ws.on('finish',()=>{
console.log('完成');
})
Comedy:
cosnt http = require('http');
const zlib = require('zlib');
const url = require('url');
const fs = require('fs');
http.createSever((req,res)=>{
let {pathname} = url.parse(req.url,true);
let filepath='www'+pathname;
fs.stat(filepath,(err,stat)=>{
if(err){
//res.setHerader('content-encoding','deflate');
res.writeHeader();
res.write('NOT FOUND');
res.end();
}else{
let rs=fs.createReadStream(filepath);
rs.on('error',()=>{ });
res.setHerader('content-encoding','gzip');
let gz = zlib.createGzip();
rs.pipe(res);
}
});
}).listen();
npm i forever -g
forever start server.js
终端关了依旧在,会自动启动
forever restart server.js 停掉再重开
forever stop server.js 停掉
forever stopall 停掉全部
'/login' => function(){}
'/reg' => function(){}
' *' => read
手机扫一扫
移动阅读更方便
你可能感兴趣的文章