From c9d11baaffb7d9d3b0a01f631cfdd3ceccf2e06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E5=98=89=E7=90=AA?= <2534384247@qq.com> Date: Thu, 3 Mar 2022 21:30:21 +0800 Subject: [PATCH] =?UTF-8?q?2022.03.03=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../big.txt" | 0 ...73\345\217\226\346\226\207\344\273\266.js" | 12 +++---- .../http\345\215\217\350\256\2561.js" | 26 ++++++++++++++ .../http\345\215\217\350\256\2562.js" | 35 +++++++++++++++++++ .../index.html" | 12 +++++++ .../one.html" | 19 ++++++++++ .../two.html" | 19 ++++++++++ 7 files changed, 116 insertions(+), 7 deletions(-) rename "\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\217\226\346\226\207\344\273\266/big.txt" => "\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\206\231\346\226\207\344\273\266/big.txt" (100%) rename "\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\217\226\346\226\207\344\273\266/\346\265\201\350\257\273\345\217\226\346\226\207\344\273\266.js" => "\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\206\231\346\226\207\344\273\266/\346\265\201\350\257\273\345\217\226\346\226\207\344\273\266.js" (79%) create mode 100644 "\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/http\345\215\217\350\256\2561.js" create mode 100644 "\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/http\345\215\217\350\256\2562.js" create mode 100644 "\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/index.html" create mode 100644 "\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/one.html" create mode 100644 "\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/two.html" diff --git "a/\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\217\226\346\226\207\344\273\266/big.txt" "b/\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\206\231\346\226\207\344\273\266/big.txt" similarity index 100% rename from "\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\217\226\346\226\207\344\273\266/big.txt" rename to "\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\206\231\346\226\207\344\273\266/big.txt" diff --git "a/\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\217\226\346\226\207\344\273\266/\346\265\201\350\257\273\345\217\226\346\226\207\344\273\266.js" "b/\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\206\231\346\226\207\344\273\266/\346\265\201\350\257\273\345\217\226\346\226\207\344\273\266.js" similarity index 79% rename from "\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\217\226\346\226\207\344\273\266/\346\265\201\350\257\273\345\217\226\346\226\207\344\273\266.js" rename to "\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\206\231\346\226\207\344\273\266/\346\265\201\350\257\273\345\217\226\346\226\207\344\273\266.js" index 06998a4..51b1a46 100644 --- "a/\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\217\226\346\226\207\344\273\266/\346\265\201\350\257\273\345\217\226\346\226\207\344\273\266.js" +++ "b/\351\233\267\345\230\211\347\220\252/2022.03.02 \346\265\201\350\257\273\345\206\231\346\226\207\344\273\266/\346\265\201\350\257\273\345\217\226\346\226\207\344\273\266.js" @@ -25,24 +25,23 @@ let fs = require('fs'); -let fd = fs.openSync('./big.txt', 'w'); +let fd = fs.createWriteStream('./big.txt', 'utf-8'); for (let i = 0; i < 600000; i++) { let str = '又冷又累又饿又困,想回宿舍睡觉!\n'; - fs.writeSync(fd, Buffer.from(str)); + fd.write(Buffer.from(str)); } -// fs.closeSync(fd); let os = require('os'); let start = os.freemem(); // 运行前空闲的内存 -let readBig = fs.createReadStream('./big.txt', {encoding: 'utf-8'}); +let readBig = fs.createReadStream('./big.txt', 'utf-8'); readBig.on('data',function(chunk){ - // console.log(chunk+'=================='); + // console.log(chunk); }); -readBig.on('open',function(fd){ +readBig.on('open',function(){ console.log("开启流"); }); @@ -54,6 +53,5 @@ readBig.on('close',function(chunk){ console.log("关闭流"); }); -fs.readFileSync('./big.txt'); let end = os.freemem(); // 运行后空闲的内存 console.log((start-end)/1024/1024); \ No newline at end of file diff --git "a/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/http\345\215\217\350\256\2561.js" "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/http\345\215\217\350\256\2561.js" new file mode 100644 index 0000000..b5e28e5 --- /dev/null +++ "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/http\345\215\217\350\256\2561.js" @@ -0,0 +1,26 @@ +let http = require('http'); + +let server = http.createServer(); + +server.on('request', function(req, res) { + + res.setHeader("Content-Type", "text/html; charset=utf-8"); + + let content = '
404 not found
'; + + let url = req.url; + + if(url === '/' || url === '/one.html') { + content = '
我是one.html页面
'; + } + else if(url === '/two.html') { + content = '
我是two.html页面
'; + } + + res.end(content); + +}) + +server.listen('8888', function() { + console.log('http://127.0.0.1:8888'); +}) \ No newline at end of file diff --git "a/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/http\345\215\217\350\256\2562.js" "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/http\345\215\217\350\256\2562.js" new file mode 100644 index 0000000..02259c2 --- /dev/null +++ "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/http\345\215\217\350\256\2562.js" @@ -0,0 +1,35 @@ +let http = require('http'); +let fs = require('fs'); + +let server = http.createServer(); + +server.on('request', function(req, res) { + + res.setHeader("Content-Type", "text/html; charset=utf-8"); + + let url = req.url; + + if(url === '/') { + fs.readFile('./index.html', function(err, data) { + res.end(data) + }) + } + else if(url === '/one') { + fs.readFile('./one.html', function(err, data) { + res.end(data) + }) + } + else if(url === '/two') { + fs.readFile('./two.html', function(err, data) { + res.end(data) + }) + } + else { + res.end('404') + } + +}) + +server.listen('8888', function() { + console.log('http://127.0.0.1:8888'); +}) \ No newline at end of file diff --git "a/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/index.html" "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/index.html" new file mode 100644 index 0000000..c5d806f --- /dev/null +++ "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/index.html" @@ -0,0 +1,12 @@ + + + + + + + Document + + +

首页

+ + \ No newline at end of file diff --git "a/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/one.html" "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/one.html" new file mode 100644 index 0000000..74c0e71 --- /dev/null +++ "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/one.html" @@ -0,0 +1,19 @@ + + + + + + + Document + + + +
俺是one.html页面
+ + \ No newline at end of file diff --git "a/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/two.html" "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/two.html" new file mode 100644 index 0000000..4f2a21f --- /dev/null +++ "b/\351\233\267\345\230\211\347\220\252/2022.03.03 http\345\215\217\350\256\256/two.html" @@ -0,0 +1,19 @@ + + + + + + + Document + + + +
俺是two.html页面
+ + \ No newline at end of file -- Gitee