diff --git "a/\345\274\240\347\247\200\350\212\263/3.02\344\275\234\344\270\232/demo01.js" "b/\345\274\240\347\247\200\350\212\263/3.02\344\275\234\344\270\232/demo01.js" new file mode 100644 index 0000000000000000000000000000000000000000..612f503453448300c53d3b560836d2972e6e4d15 --- /dev/null +++ "b/\345\274\240\347\247\200\350\212\263/3.02\344\275\234\344\270\232/demo01.js" @@ -0,0 +1,25 @@ +let fs = require("fs"); +let os = require('os'); +let start = os.freemem(); +let fd = fs.openSync('1.txt','w'); +for(let k=0;k<50000;k++){ + fs.writeFileSync('big01.txt','大文件\n',{flag:'a'}); +} +fs.closeSync(fd); +let end = os.freemem(); +console.log((start-end)/1024/1024); +fs.closeSync(fd); + +//流 + + +let startMes1 = os.freemem(); +let writeStream=fs.createWriteStream('big02.txt',{flag:'a'}); + +for(let n=0;n<50000;n++){ + writeStream.write('大文件\n') +} +writeStream.close(); + +let endMes1 = os.freemem(); +console.log((startMes1 - endMes1) / 1024 / 1024); \ No newline at end of file diff --git "a/\345\274\240\347\247\200\350\212\263/3.03\344\275\234\344\270\232/homework.js" "b/\345\274\240\347\247\200\350\212\263/3.03\344\275\234\344\270\232/homework.js" new file mode 100644 index 0000000000000000000000000000000000000000..d43533c5be0b1a2085415e712c588a66d4817e8d --- /dev/null +++ "b/\345\274\240\347\247\200\350\212\263/3.03\344\275\234\344\270\232/homework.js" @@ -0,0 +1,14 @@ + + let http = require("http"); + let fs = require("fs"); + let server=http.createServer(); + server.on('request', (req, res) => { + let url = req.url; + if(url.indexOf("page")!=-1){ + let page=url.split("?")[1].split('=')[1] + let bf=fs.readFileSync('./html/'+page+'.txt'); + res.write(bf); + } + res.end(); + }); + server.listen(80); \ No newline at end of file