<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by peter davis on Medium]]></title>
        <description><![CDATA[Stories by peter davis on Medium]]></description>
        <link>https://medium.com/@petersdavis?source=rss-a831eb56b74------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8C3tT89boXsmcDGj0s6kXA.jpeg</url>
            <title>Stories by peter davis on Medium</title>
            <link>https://medium.com/@petersdavis?source=rss-a831eb56b74------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 05:36:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@petersdavis/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Adventures in Streaming to Http Requests in NodeJS]]></title>
            <link>https://medium.com/@petersdavis/adventures-in-streaming-to-http-requests-in-nodejs-9d87d57e66c6?source=rss-a831eb56b74------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d87d57e66c6</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[transform]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[peter davis]]></dc:creator>
            <pubDate>Tue, 31 May 2022 17:04:37 GMT</pubDate>
            <atom:updated>2022-05-31T17:17:36.727Z</atom:updated>
            <content:encoded><![CDATA[<p>TLDR;</p><p>After two days of searching I found that the internet lacked simple instructions for streaming a readable stream into an http requests and then piping the response into a writeable stream.</p><p>Just the working code:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.thiscodeworks.com%2Fembed%2F629647130267f50015ffcfde&amp;dntp=1&amp;display_name=thiscodeworks&amp;url=https%3A%2F%2Fwww.thiscodeworks.com%2Fembed%2F629647130267f50015ffcfde&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=thiscodeworks" width="620" height="595" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8b62026972cfac9e52e0936a900de51/href">https://medium.com/media/c8b62026972cfac9e52e0936a900de51/href</a></iframe><p>Gotchas:</p><ol><li>You must call req.end() before you can expect any response from the server — if you don’t call req.end() your code will just hang while it waits.</li><li>_flush(callback) is called on the transform when its finished consuming the pipe and when you call the callback() thats when whatever transforms downstream get closed, so you need to connect the callback into the request’s response logic and call it when the response’s “end” event triggers.</li><li>Its a bit confusing but transform.write() adds data to the head of the pipe, transform.push() adds data to the tail — I think the response object is technically a ReadStream, but I couldn’t figure out any way to pipe the response to the WriteStream of the transform — So instead of doing that I just handle the ‘data’ and the ‘end’ events of the ClientResponse.</li><li>An instance of a Transform is a single use consumable thing. So if you try to reuse the instance you will get an infinite loop. That’s why the call to new Transform() needs to be wrapped in a generator function.</li></ol><p>It’s okay internet. Nobodies perfect. And hey — after five years as a software developer I finally did a thing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d87d57e66c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>