Page 134 - Nodejs 교과서 개정2판
P. 134
buffer-memory.js
const fs = require('fs');
console.log('before: ', process.memoryUsage().rss);
const data1 = fs.readFileSync('./big.txt');
fs.writeFileSync('./big2.txt', data1);
console.log('buffer: ', process.memoryUsage().rss);
콘솔
$ node buffer-memory
before: 18137088
buffer: 1019133952
ী .#؍ ݫݽܻ ਊ ࣽधрী (#ܳ ֈणפ (# ਊ ੌਸ ࠂࢎೞӝ ਤ೧ ݫݽܻী
ੌਸ ݽف ৢ۰ك റ writeFileSyncܳ ࣻ೯೮ӝ ٸޙੑפ
ߣীח झܿਸ ࢎਊೞৈ ੌਸ CJH UYU۽ ࠂࢎ೧ࠁѷणפ
stream-memory.js
const fs = require('fs');
console.log('before: ', process.memoryUsage().rss);
const readStream = fs.createReadStream('./big.txt');
const writeStream = fs.createWriteStream('./big3.txt');
readStream.pipe(writeStream);
readStream.on('end', () => {
console.log('stream: ', process.memoryUsage().rss);
});
콘솔
$ node stream-memory
before: 18087936
stream: 62472192
झܿਸ ࢎਊ೧ࢲ ੌਸ ࠂࢎ೮؊פ ݫݽܻܳ .#߆ী ରೞ ঋणפ ߑध (# ਊਸ ର
೮؍ Ѫী ࠺ೞݶ ষդ ѐࢶ ബҗੑפ ੌਸ ઑпղয ߡಌ ױਤ۽ ҂ӝ ٸޙੑפ ۧѱ झ
ܿਸ ࢎਊೞݶ ബҗਵ۽ ؘఠܳ ࣠ೡ ࣻ णפ ز࢚ э ੌٜਸ ࣠ೡ ٸ ۞ೠ ਬ۽