标签:数据库 reads pipe das 加密 stop end flat cti
https://www.cnblogs.com/lalalagq/p/9749680.html
sf.readFile(‘www${pathname}‘,(err,buffer)=>{ res.write(buffer); }); 1.占用内存; 2.资源使用不均匀 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(404); 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(8520);
标签:数据库 reads pipe das 加密 stop end flat cti
原文地址:https://www.cnblogs.com/comedy/p/11789286.html