From 3789667ee47f0a5c4123d6e46da791a92954556b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=8C?= <70946690> Date: Wed, 2 Mar 2022 17:17:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?3.2=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\345\210\230\346\226\214/bata.js" | 25 +++++++++++++++++++++++++ "\345\210\230\346\226\214/big.txt" | 0 2 files changed, 25 insertions(+) create mode 100644 "\345\210\230\346\226\214/bata.js" create mode 100644 "\345\210\230\346\226\214/big.txt" diff --git "a/\345\210\230\346\226\214/bata.js" "b/\345\210\230\346\226\214/bata.js" new file mode 100644 index 0000000..1b1d9fe --- /dev/null +++ "b/\345\210\230\346\226\214/bata.js" @@ -0,0 +1,25 @@ +/** + * 作业 + * 创建个大文件,分别用传统方式于流方式,再计算下内存的消耗 + */ +let fs =require("fs"); + +//传统方法创建 +let os= require("os"); +let startMes=os.freemem(); +let fd = fs.openSync("big.txt", 'r'); +let bf3 = Buffe + r.alloc(6.1 * 1024 * 1024); +fs.readSync(fd, bf3, 0, 6.1 * 1024 * 1024); +console.log(bf3.toString()); + +let endMes = os.freemem(); +console.log(startMes); +console.log(endMes); +console.log((startMes - endMes) / 1024 / 1024); +setTimeout(function(){ +fs.closeSync(fd); +},1000); + +//流 +let readStream=fs.createReadStream('small.txt','utf-8'); diff --git "a/\345\210\230\346\226\214/big.txt" "b/\345\210\230\346\226\214/big.txt" new file mode 100644 index 0000000..e69de29 -- Gitee From 0651b68b43c21581f0c8dfe8bfffbea7c3626a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=96=8C?= <70946690> Date: Wed, 2 Mar 2022 17:35:13 +0800 Subject: [PATCH 2/2] bujiao --- "\345\210\230\346\226\214/2.28/bata1.js" | 16 ++++++++++++++++ .../3.1/bata.js" | 0 .../3.1/big.txt" | 0 3 files changed, 16 insertions(+) create mode 100644 "\345\210\230\346\226\214/2.28/bata1.js" rename "\345\210\230\346\226\214/bata.js" => "\345\210\230\346\226\214/3.1/bata.js" (100%) rename "\345\210\230\346\226\214/big.txt" => "\345\210\230\346\226\214/3.1/big.txt" (100%) diff --git "a/\345\210\230\346\226\214/2.28/bata1.js" "b/\345\210\230\346\226\214/2.28/bata1.js" new file mode 100644 index 0000000..726da73 --- /dev/null +++ "b/\345\210\230\346\226\214/2.28/bata1.js" @@ -0,0 +1,16 @@ +// 创建100文件吧,内容自便,读取文件把这100个文件的内容给我拼接起来输出,可以写在一个文件里面也可以输出 +let fs = require('fs'); +let func = function (num) { + for(let i =0;i<=num;i++){ + let fg = fs.openSync('./c.txt','a') + let fd = fs.openSync(`./File${i}.txt`,'w') + let content = Math.ceil(Math.random()*10) + fs.writeSync(fd,`${content}`) + fs.writeSync(fg,`${content} `) + fs.closeSync(fd) + } +} +func(100); + + let buffer=fs.readFileSync("./c.txt",{flag:'r',encoding:'utf-8'}); + console.log(buffer.toString()); diff --git "a/\345\210\230\346\226\214/bata.js" "b/\345\210\230\346\226\214/3.1/bata.js" similarity index 100% rename from "\345\210\230\346\226\214/bata.js" rename to "\345\210\230\346\226\214/3.1/bata.js" diff --git "a/\345\210\230\346\226\214/big.txt" "b/\345\210\230\346\226\214/3.1/big.txt" similarity index 100% rename from "\345\210\230\346\226\214/big.txt" rename to "\345\210\230\346\226\214/3.1/big.txt" -- Gitee