Page 133 - Nodejs 교과서 개정2판
P. 133
pipeח झܿ ࢎী ৈ۞ ߣ োѾೡ ࣻ णפ ٘ח ੌਸ ੍ റ H[JQ ߑधਵ۽ ୷ೞח ٘ੑ
פ
gzip.js
const zlib = require('zlib');
const fs = require('fs');
const readStream = fs.createReadStream('./readme4.txt');
const zlibStream = zlib.createGzip();
const writeStream = fs.createWriteStream('./readme4.txt.gz');
readStream.pipe(zlibStream).pipe(writeStream);
֢٘ীࢲח ੌਸ ୷ೞח [MJCۄח ݽٕب ઁҕפ ଼ীࢲח ݆ ࢎਊೞ ঋਵ۽ ٮ۽ ࢸݺೞ
ח ঋणפ ݅ [MJC createGzipۄח ݫࢲ٘о झܿਸ ਗೞ۽ readStreamҗ writeStream рী
ࢲ ೝਸ ೡ ࣻ णפ ߡಌ ؘఠо ׳غо H[JQ ୷ਸ Ѣ റ ੌ۽ ॄפ
콘솔
$ node gzip
SFBENF UYU H[ ੌ ࢤࢿؾפ ୷ػ ੌۄ ղਊޛਸ ੍ӝח ൨ٟפ
ۧѱ ੌਸ ݽف ߡಌী ೞח readFile ݫࢲ٘৬ ࠗ࠙ਵ۽ աׇ ੍ח createRead Stream ݫࢲ٘ܳ
ঌইࠌणפ ف ݫࢲ٘ ݫݽܻ ࢎਊ ݃ա ܲ पઁ۽ ഛੋ೧ࠁѷणפ
(# ਊ ఫझ ੌਸ ݅٘ח ٘ੑפ ݢ അ ٘ۄ࠳ী ࠙ೠ ਊ թই ח ഛੋೞ
Ҋ प೯೧ঠ פ दр ઑӘ ݆ ࣗਃؼ ࣻ णפ
createBigFile.js
const fs = require('fs');
const file = fs.createWriteStream('./big.txt');
for (let i = 0; i <= 10000000; i++) {
file.write('안녕하세요. 엄청나게 큰 파일을 만들어 볼 것입니다. 각오 단단히 하세요!\n');
}
file.end();
콘솔
$ node createBigFile
readFile ݫࢲ٘ܳ ࢎਊೞৈ CJH UYUܳ CJH UYU۽ ࠂࢎ೧ࠁѷणפ