Page 130 - Nodejs 교과서 개정2판
P. 130
• concat(배열) ߓৌ উী ٚ ߡಌٜਸ ೞա۽ פ
• alloc(바이트) ࠼ ߡಌܳ ࢤࢿפ ߄ܳ ੋࣻ۽ ֍ਵݶ ೧ ӝ ߡಌо ࢤࢿؾפ
readFile ߑध ߡಌо ಞܻೞӝח ೞ݅ ޙઁب णפ ݅ড ਊ .#ੋ ੌ ਵݶ ੍ਸ ٸ
ݫݽܻী .# ߡಌܳ ٜ݅যঠ פ সਸ زदী ৌ ѐ݅ ೧ب (#ী ׳ೞח ݫݽܻо ࢎਊؾפ
ౠ ࢲߡۢ ݻ ݺ ਊೡ ݽܰח ജ҃ীࢲח ݫݽܻ ޙઁо ߊࢤೡ ࣻ णפ
ژೠ ݽٚ ղਊਸ ߡಌী ॵ റীঠ زਵ۽ ֈযо۽ ੌ ੍ӝ ୷ ੌ ॳӝ ١ ઑਸ ো׳
ই ೡ ٸ ݒߣ ਊਸ ߡಌ۽ ܻ೧ঠ ױ҅۽ ֈযт ࣻ णפ
Ӓېࢲ ߡಌ ӝܳ ѱ ݅ٚ റ ৈ۞ ߣਵ۽ աׇ ࠁղח ߑध ١೮णפ ܳ ٜݶ ߡಌ .#ܳ ݅ٚ
റ .# ੌਸ ߔ ߣী Ѧࢲ աׇ ࠁղח Ѫੑפ ۽ॄ ݫݽܻ .#۽ .# ੌਸ ࣠ೡ ࣻ ण
פ ܳ ಞܻೞѱ ݅ٚ Ѫ झܿੑפ
§ Ӓܿ झܿ
ੌਸ ੍ח झܿ ݫࢲ٘۽ח createReadStream णפ җ э ࢎਊפ
readme3.txt
저는 조금씩 조금씩 나눠서 전달됩니다. 나눠진 조각을 chunk라고 부릅니다.
createReadStream.js
const fs = require('fs');
const readStream = fs.createReadStream('./readme3.txt', { highWaterMark: 16 });
const data = [];
readStream.on('data', (chunk) => {
data.push(chunk);
console.log('data :', chunk, chunk.length);
});
readStream.on('end', () => {
console.log('end :', Buffer.concat(data).toString());
});