{"id":886,"date":"2026-05-20T09:52:05","date_gmt":"2026-05-20T01:52:05","guid":{"rendered":"https:\/\/junai.ai\/blog\/nodejs-stream-10\/"},"modified":"2026-05-20T09:52:05","modified_gmt":"2026-05-20T01:52:05","slug":"nodejs-stream-10","status":"publish","type":"post","link":"https:\/\/junai.ai\/blog\/nodejs-stream-10\/","title":{"rendered":"Stream \u2014 \ub300\uc6a9\ub7c9 \ud30c\uc77c\uc744 \uba54\ubaa8\ub9ac \uac71\uc815 \uc5c6\uc774"},"content":{"rendered":"\n<!-- WordPress REST API \ubc1c\ud589\uc6a9 HTML (\uc790\ub3d9 \uc0dd\uc131) -->\n<!-- WP-FEATURED-MEDIA-ID: 832 -->\n<div style=\"max-width:800px;margin:0 auto;\">\n<style>\n:root {--color-primary:#059669;--color-accent:#10b981;--color-bg:#fafbfc;--color-bg-card:#fff;--color-text:#1a202c;--color-text-muted:#64748b;--hero-start:#064e3b;--hero-end:#059669;}\n*{box-sizing:border-box;}\n.container{max-width:760px;margin:0 auto;padding:0 24px 80px;}\n.hero{background:linear-gradient(135deg,var(--hero-start) 0%,var(--hero-end) 100%);color:#fff;padding:80px 24px 60px;text-align:center;}\n.hero .eyebrow{display:inline-block;font-size:14px;color:#6ee7b7;font-weight:700;letter-spacing:0.1em;text-transform:uppercase;margin-bottom:14px;}\n.hero h1{font-size:36px;margin:0 0 16px;line-height:1.3;font-weight:800;}\n.hero p{color:#d1fae5;font-size:18px;max-width:640px;margin:0 auto;line-height:1.6;}\n.hero img{width:100%;max-width:640px;height:auto;margin:32px auto 0;border-radius:10px;display:block;}\narticle{padding-top:48px;}\narticle h2{font-size:26px;margin:56px 0 20px;padding-left:14px;border-left:5px solid var(--color-accent);line-height:1.4;}\narticle h3{font-size:19px;margin:32px 0 12px;color:var(--color-primary);}\narticle p{margin:16px 0;}\narticle strong{color:var(--color-primary);font-weight:700;}\narticle code{background:#d1fae5;padding:2px 8px;border-radius:4px;font-family:'SF Mono',Menlo,Consolas,monospace;font-size:14px;color:#065f46;}\n.databox{background:#d1fae5;border-left:4px solid var(--color-accent);padding:16px 20px;margin:24px 0;border-radius:0 8px 8px 0;font-size:15.5px;}\n.databox strong{color:var(--color-primary);}\n.warnbox{background:linear-gradient(135deg,#fef3c7 0%,#fde68a 100%);padding:16px 20px;margin:24px 0;border-radius:8px;font-size:15.5px;}\n.tablewrap{overflow-x:auto;-webkit-overflow-scrolling:touch;margin:22px 0;}\ntable{width:100%;border-collapse:collapse;font-size:15px;background:var(--color-bg-card);}\nth,td{padding:11px 12px;text-align:left;border-bottom:1px solid #e2e8f0;vertical-align:top;}\nth{background:#f1f5f9;font-weight:700;color:#0f172a;}\ntd:first-child,th:first-child{font-weight:700;}\n@media (max-width:560px){.tablewrap table,.tablewrap thead,.tablewrap tbody,.tablewrap tr,.tablewrap th,.tablewrap td{display:block;width:auto;}.tablewrap thead{display:none;}.tablewrap tr{margin:0 0 14px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden;}.tablewrap td{border:none;border-bottom:1px solid #f1f5f9;padding:9px 14px;}.tablewrap td:first-child{background:#f1f5f9;font-weight:800;font-size:15.5px;}.tablewrap td:last-child{border-bottom:none;}.tablewrap td[data-label]::before{content:attr(data-label) \" \u2014 \";font-weight:700;color:var(--color-primary);}}\n.code-block{background:#0f172a;color:#e2e8f0;padding:16px 20px;border-radius:8px;font-family:'SF Mono',Menlo,Consolas,monospace;font-size:14px;line-height:1.6;margin:20px 0;overflow-x:auto;white-space:pre;}\n.cta{background:linear-gradient(135deg,#059669 0%,#10b981 100%);color:#fff;padding:28px 24px;border-radius:12px;margin:48px 0 0;text-align:center;}\n.cta h3{color:#fff;margin:0 0 8px;font-size:20px;}\n.cta p{color:#d1fae5;margin:0;font-size:15.5px;}\n.footer-nav{margin-top:32px;padding-top:20px;border-top:1px solid #e2e8f0;font-size:14px;color:var(--color-text-muted);}\n.footer-nav a{color:var(--color-primary);text-decoration:none;}\n@media (max-width:480px){.hero h1{font-size:26px;}.hero p{font-size:16px;}article h2{font-size:21px;}article h3{font-size:17px;}body{font-size:16px;}}\n<\/style>\n<section class=\"hero\">\n  <span class=\"eyebrow\">Node.js \uad50\uc7ac \u00b7 10\ud3b8 \u00b7 Stream<\/span>\n  <h1>Stream \u2014 \ub300\uc6a9\ub7c9 \ud30c\uc77c\uc744 \uba54\ubaa8\ub9ac \uac71\uc815 \uc5c6\uc774<\/h1>\n  <p>1GB \ud30c\uc77c\uc744 \ud1b5\uc9f8\ub85c \uba54\ubaa8\ub9ac\uc5d0 \uc62c\ub9ac\uc9c0 \ub9d0\uace0 \uccad\ud06c\ub85c \ud758\ub9ac\uc790.<\/p>\n  <img decoding=\"async\" src=\"https:\/\/junai.ai\/blog\/wp-content\/uploads\/2026\/05\/hero-5-65.jpg\" alt=\"\ub370\uc774\ud130\uac00 \uccad\ud06c\ub85c \ud30c\uc774\ud504\ub77c\uc778\uc744 \ud750\ub974\ub294 \ucee8\uc149 \uc544\uc774\uc18c\uba54\ud2b8\ub9ad \uc77c\ub7ec\uc2a4\ud2b8\">\n<\/section>\n\n<div class=\"container\">\n<article>\n\n<p>6\ud3b8\uc5d0\uc11c \ubcf8 <code>fs.readFile<\/code> \uc758 \ud568\uc815 \u2014 1GB \ud30c\uc77c\uc744 \uc77d\uc73c\uba74 1GB \uba54\ubaa8\ub9ac\ub97c \ud1b5\uc9f8\ub85c \ucc28\uc9c0\ud55c\ub2e4. 100\uba85\uc774 \ub3d9\uc2dc \uc811\uc18d\ud574\uc11c \uac19\uc740 \uc77c\uc744 \ud558\uba74 100GB. \uc11c\ubc84\uac00 OOM \uc73c\ub85c \uc8fd\ub294\ub2e4.<\/p>\n\n<p>\ud574\ub2f5\uc774 <strong>Stream<\/strong>. \ud30c\uc77c\uc744 \uc791\uc740 <strong>\uccad\ud06c(chunk)<\/strong> \ub2e8\uc704\ub85c \ub098\ub220 \uc77d\uace0, \ucc98\ub9ac\ud558\uc790\ub9c8\uc790 \ud758\ub824\ubcf4\ub0b4\uace0, \ub610 \ub2e4\uc74c \uccad\ud06c. \ucd5c\ub300 \uba54\ubaa8\ub9ac \uc0ac\uc6a9\ub7c9\uc740 \uccad\ud06c \ud06c\uae30 \u00d7 \ub3d9\uc2dc \ucc98\ub9ac \uac1c\uc218 \u2014 1GB \ud30c\uc77c\ub3c4 16KB \uba54\ubaa8\ub9ac\ub85c \ucda9\ubd84. Node \uc758 \uc9c4\uc9dc \ubb34\uae30 \uc911 \ud558\ub098.<\/p>\n\n<h2>1. Stream 3\uc885 \u2014 Readable, Writable, Transform<\/h2>\n\n<p>Stream \uc740 \ub370\uc774\ud130\uc758 \ud750\ub984 \ubc29\ud5a5\uc5d0 \ub530\ub77c \uc138 \uac00\uc9c0\uac00 \uc788\ub2e4.<\/p>\n\n<div class=\"tablewrap\">\n<table>\n<thead><tr><th>\uc885\ub958<\/th><th>\ubc29\ud5a5<\/th><th>\uc608\uc2dc<\/th><\/tr><\/thead>\n<tbody>\n<tr><td>Readable<\/td><td data-label=\"\ubc29\ud5a5\">\uc77d\uae30 \u2014 \ub370\uc774\ud130\ub97c \ub0b4\ubcf4\ub0c4<\/td><td data-label=\"\uc608\uc2dc\"><code>fs.createReadStream<\/code>, HTTP request<\/td><\/tr>\n<tr><td>Writable<\/td><td data-label=\"\ubc29\ud5a5\">\uc4f0\uae30 \u2014 \ub370\uc774\ud130\ub97c \ubc1b\uc74c<\/td><td data-label=\"\uc608\uc2dc\"><code>fs.createWriteStream<\/code>, HTTP response<\/td><\/tr>\n<tr><td>Transform<\/td><td data-label=\"\ubc29\ud5a5\">\uc911\uac04 \uac00\uacf5 \u2014 \ubc1b\uc544\uc11c \ubcc0\ud615 \ud6c4 \ub0b4\ubcf4\ub0c4<\/td><td data-label=\"\uc608\uc2dc\">\uc555\ucd95(gzip)\u00b7\uc554\ud638\ud654\u00b7\ub77c\uc778 \ubd84\ub9ac<\/td><\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n\n<p>(\uc5c4\ubc00\ud788\ub294 4\ubc88\uc9f8 Duplex \uac00 \uc788\uc9c0\ub9cc \uc2e4\uc804\uc5d0\uc11c \uac70\uc758 \uc548 \uc4f4\ub2e4.)<\/p>\n\n<p>\uc774 \uc14b\uc744 <code>pipe()<\/code> \ub610\ub294 <code>pipeline()<\/code> \uc73c\ub85c <strong>\ub808\uace0\ucc98\ub7fc \uc5f0\uacb0<\/strong>\ud558\ub294 \uac8c Stream \uc758 \uc815\uc218.<\/p>\n\n<h2>2. \ud30c\uc77c \ubcf5\uc0ac \u2014 readFile vs createReadStream<\/h2>\n\n<p>\uac19\uc740 \uc791\uc5c5\uc744 \ub450 \uac00\uc9c0\ub85c.<\/p>\n\n<div class=\"code-block\">\/\/ \u274c 1GB \ud30c\uc77c\uc774\uba74 1GB \uba54\ubaa8\ub9ac\nimport fs from &#8216;node:fs\/promises&#8217;;\nconst data = await fs.readFile(&#8216;big.bin&#8217;);\nawait fs.writeFile(&#8216;copy.bin&#8217;, data);\n\n\/\/ \u2705 16KB \uccad\ud06c\uc529, \uba54\ubaa8\ub9ac \uac70\uc758 \uc548 \uc500\nimport fs from &#8216;node:fs&#8217;;\nimport { pipeline } from &#8216;node:stream\/promises&#8217;;\n\nawait pipeline(\n  fs.createReadStream(&#8216;big.bin&#8217;),\n  fs.createWriteStream(&#8216;copy.bin&#8217;),\n);<\/div>\n\n<p><code>pipeline<\/code> \uc774 \ub450 stream \uc744 \uc5f0\uacb0\ud55c\ub2e4. \ub370\uc774\ud130\uac00 \uccad\ud06c \ub2e8\uc704\ub85c \ud750\ub974\uace0, \ud55c \ucabd\uc774 \ube60\ub974\uba74 \uc790\ub3d9\uc73c\ub85c \uc18d\ub3c4\ub97c \ub9de\ucd98\ub2e4(<strong>backpressure<\/strong>). <strong>\uac19\uc740 \uacb0\uacfc\uc778\ub370 \uba54\ubaa8\ub9ac \uc0ac\uc6a9\ub7c9\uc740 1\ub9cc \ubd84\uc758 1<\/strong>.<\/p>\n\n<h2>3. Transform \u2014 \ud750\ub984 \uc911\uac04\uc5d0 \ubcc0\ud658<\/h2>\n\n<p>\uc2e4\uc804 \uac00\uc7a5 \uc790\uc8fc \uc4f0\ub294 \ud328\ud134. \uc555\ucd95\u00b7\ubcf5\ud638\ud654\u00b7\ub77c\uc778 \ucc98\ub9ac \ub4f1\uc774 \ubaa8\ub450 Transform.<\/p>\n\n<div class=\"code-block\">\/\/ gzip \uc555\ucd95\nimport fs from &#8216;node:fs&#8217;;\nimport zlib from &#8216;node:zlib&#8217;;\nimport { pipeline } from &#8216;node:stream\/promises&#8217;;\n\nawait pipeline(\n  fs.createReadStream(&#8216;log.txt&#8217;),\n  zlib.createGzip(),\n  fs.createWriteStream(&#8216;log.txt.gz&#8217;),\n);<\/div>\n\n<p><code>zlib.createGzip()<\/code> \uc774 \uc911\uac04 Transform. \uc785\ub825\uc73c\ub85c \ubc1b\uc740 \uccad\ud06c\ub97c \uc555\ucd95\ud574\uc11c \ub2e4\uc74c\uc73c\ub85c \ud758\ub9b0\ub2e4. \ub611\uac19\uc774 <code>zlib.createGunzip()<\/code> \uc740 \ud480\uae30.<\/p>\n\n<h2>4. HTTP \uc751\ub2f5\uacfc \uacb0\ud569 \u2014 \ud070 \ud30c\uc77c \ub2e4\uc6b4\ub85c\ub4dc<\/h2>\n\n<p>\uc2e4\uc804 \u2014 \uc0ac\uc6a9\uc790\uac00 \ud070 \ud30c\uc77c\uc744 \ub2e4\uc6b4\ub85c\ub4dc\ud560 \ub54c \uba54\ubaa8\ub9ac\uc5d0 \ud1b5\uc9f8\ub85c \uc62c\ub9ac\uc9c0 \ub9d0\uace0 \uc989\uc2dc Stream \uc73c\ub85c.<\/p>\n\n<div class=\"code-block\">import http from &#8216;node:http&#8217;;\nimport fs from &#8216;node:fs&#8217;;\nimport { pipeline } from &#8216;node:stream\/promises&#8217;;\n\nhttp.createServer(async (req, res) =&gt; {\n  if (req.url === &#8216;\/download&#8217;) {\n    res.setHeader(&#8216;Content-Type&#8217;, &#8216;application\/octet-stream&#8217;);\n    res.setHeader(&#8216;Content-Disposition&#8217;, &#8216;attachment; filename=big.bin&#8217;);\n    try {\n      await pipeline(\n        fs.createReadStream(&#8216;.\/big.bin&#8217;),\n        res,                          \/\/ \u2190 res \uc790\uccb4\uac00 Writable Stream\n      );\n    } catch (err) {\n      console.error(&#8216;\uc804\uc1a1 \uc2e4\ud328:&#8217;, err);\n    }\n  }\n}).listen(3000);<\/div>\n\n<p>\ud575\uc2ec\uc740 <strong>HTTP <code>res<\/code> \ub3c4 Writable Stream<\/strong> \uc774\ub77c\ub294 \uac83. \ud30c\uc77c\uc744 \uba54\ubaa8\ub9ac\uc5d0 \uc62c\ub9ac\uc9c0 \uc54a\uace0 \uc989\uc2dc \ud074\ub77c\uc774\uc5b8\ud2b8\ub85c \ud758\ub9ac\ub2c8\uae4c \uc751\ub2f5\uc774 \ube68\ub9ac \uc2dc\uc791\ub418\uace0, \ub3d9\uc2dc \uc0ac\uc6a9\uc790\uac00 \ub9ce\uc544\ub3c4 \uba54\ubaa8\ub9ac \ud3ed\ubc1c \uc5c6\uc74c.<\/p>\n\n<div class=\"databox\">\n<strong>Node 18+ \uc758 fetch + Response.body<\/strong> \u2014 \uc678\ubd80 API \uc5d0\uc11c \ubc1b\uc740 \ub370\uc774\ud130\ub97c \uadf8\ub300\ub85c \ub2e4\uc6b4\uc2a4\ud2b8\ub9bc\uc73c\ub85c \ud758\ub9b4 \ub54c <code>(await fetch(url)).body<\/code> \ub3c4 Web Stream. <code>Readable.fromWeb()<\/code> \ub85c Node Stream \uc73c\ub85c \ubcc0\ud658\ud574\uc11c pipeline \uc5d0 \uc5f0\uacb0 \uac00\ub2a5.\n<\/div>\n\n<h2>5. async iterator \u2014 \ubaa8\ub358 stream \uc18c\ube44\ubc95<\/h2>\n\n<p>Node 10+ \ubd80\ud130 Readable Stream \uc744 <code>for await<\/code> \ub85c \uc9c1\uc811 \uc21c\ud68c\ud560 \uc218 \uc788\ub2e4. \uc774\uac8c \uac00\uc7a5 \uc790\uc5f0\uc2a4\ub7ec\uc6b4 \ubaa8\ub358 \ud328\ud134.<\/p>\n\n<div class=\"code-block\">import fs from &#8216;node:fs&#8217;;\nimport readline from &#8216;node:readline&#8217;;\n\nconst rl = readline.createInterface({\n  input: fs.createReadStream(&#8216;access.log&#8217;),\n  crlfDelay: Infinity,\n});\n\nlet count = 0;\nfor await (const line of rl) {\n  if (line.includes(&#8216;ERROR&#8217;)) count++;\n}\nconsole.log(`\uc5d0\ub7ec ${count}\uac74`);<\/div>\n\n<p>1GB \ub85c\uadf8\ub3c4 \ub77c\uc778 \ub2e8\uc704\ub85c \ud758\ub9ac\uba74\uc11c \ucc98\ub9ac. <code>for await<\/code> \uc548\uc5d0\uc11c <code>await<\/code> \ub97c \ub610 \uc368\ub3c4 \uc790\uc5f0\uc2a4\ub7fd\uac8c \ub3d9\uc791. \uc61b <code>data<\/code> \uc774\ubca4\ud2b8 + <code>end<\/code> \uc774\ubca4\ud2b8 \ud578\ub4e4\ub7ec \ud328\ud134\uc740 \uac70\uc758 \uc548 \uc4f0\uac8c \ub410\ub2e4.<\/p>\n\n<h3>\uc694\uc57d \u2014 10\ud3b8 \uc88c\ud45c<\/h3>\n\n<p>\uc5ec\uae30\uae4c\uc9c0 \uc815\ub9ac. Stream \uc758 \ud575\uc2ec \ub450 \uac00\uc9c0 \u2014 <strong>\uccad\ud06c \ub2e8\uc704 \ucc98\ub9ac<\/strong> (\uba54\ubaa8\ub9ac \uc808\uc57d) + <strong>backpressure \uc790\ub3d9<\/strong> (\uc18d\ub3c4 \uc870\uc808). \uc885\ub958\ub294 <strong>Readable\u00b7Writable\u00b7Transform<\/strong> 3\uc885, \uc5f0\uacb0\uc740 <code>pipeline<\/code>(\uc5d0\ub7ec \ucc98\ub9ac \uc790\ub3d9), \uc18c\ube44\ub294 <code>for await<\/code> \uac00 \ubaa8\ub358. \ud070 \ud30c\uc77c \ub2e4\ub8e8\uae30\u00b7\ub85c\uadf8 \ucc98\ub9ac\u00b7HTTP \uc751\ub2f5\u00b7\uc555\ucd95 \ubaa8\ub450 Stream \uc774 \uc815\ub2f5. \ub2e4\uc74c \ud3b8\uc5d0\uc11c \ubc14\uc774\ub108\ub9ac \ub370\uc774\ud130 \ub2e4\ub8e8\ub294 <strong>Buffer<\/strong> \ub97c \ubcf8\ub2e4.<\/p>\n\n<div class=\"cta\">\n<h3>\ub2e4\uc74c \ud3b8 \uc608\uace0 \u2014 Buffer<\/h3>\n<p>\ubc14\uc774\ub108\ub9ac \ub370\uc774\ud130\ub97c \ub2e4\ub8e8\ub294 Node \uc758 \uae30\ubcf8\ud615. 11\ud3b8.<\/p>\n<\/div>\n\n<div class=\"footer-nav\">\n\uc2dc\ub9ac\uc988 \u00b7 <a href=\"https:\/\/junai.ai\/blog\/category\/nodejs\/\">\uc27d\uac8c \ubc30\uc6b0\ub294 Node.js<\/a> \u00b7 \uc774\uc804: <a href=\"https:\/\/junai.ai\/blog\/nodejs-callback-promise-async-9\/\">Ch.9 \ube44\ub3d9\uae30 \ud328\ud134<\/a>\n<\/div>\n\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Node Stream \u2014 Readable\u00b7Writable\u00b7Transform 3\uc885, pipeline\u00b7for await. 1GB \ud30c\uc77c \uccad\ud06c \ucc98\ub9ac. \uad50\uc7ac 10\ud3b8.<\/p>\n","protected":false},"author":1,"featured_media":832,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-886","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nodejs"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/comments?post=886"}],"version-history":[{"count":0,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/posts\/886\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media\/832"}],"wp:attachment":[{"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/media?parent=886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/categories?post=886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/junai.ai\/blog\/wp-json\/wp\/v2\/tags?post=886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}