title: How to use node js transform stream as a read stream?
body: <p>I am attempting to download, modify in place, and re-upload a file to Amazon S3 using the AWS-SDK in node.js. I am new to node, and after some googling, I opted to try implementing this logic using streams. I created a custom transform stream by subclassing <code>stream.Transform</code> and supplying a <code>transform</code> function. My current implementation is:</p>
  
  <pre><code>// Download and modify file.
  var outputStream = s3.getObject(getParams).
      createReadStream().
      pipe(transformStream);
  
  // Upload modified file by passing outputStream as body to s3.putObject.
  // s3.putObjectWrapper is a promise wrapper for the api function putObject.
  s3.putObjectWrapper({body: outputStream, ...}).
      then((data) =&gt; {
          logger.debug("Put Success: ", {data: data});
      }).
      catch((err) =&gt; {
          logger.error("Put Error: ", {error: err});
      });
  </code></pre>
  
  <p>Which yields the following error output:</p>
  
  <pre><code>error: Put Error: message=Cannot determine length of [object Object], objectMode=false, highWaterMark=16384, head=null, tail=null, length=0, length=0, pipes=null, pipesCount=0, flowing=null, ended=false, endEmitted=false, reading=false, sync=false, needReadable=true, emittedReadable=false, readableListening=false, resumeScheduled=false, defaultEncoding=utf8, ranOut=false, awaitDrain=0, readingMore=false, decoder=null, encoding=null, readable=true, domain=null, end=function
  </code></pre>
  
  <p>I have read the node documentation on streams here (see link below). I did not find them helpful and I am unsure if I also have to implement stream.Read methods in my custom transform stream class, of which <code>transformStream</code> is an instance, to support readability of the stream. Note also that the function s3.putObject accepts a buffer, stream, or string as its body. So, if I could implement the same functionality using a buffer instead of passing a stream to <code>putObject</code> that would be useful.
  node.js streams: <a href="https://nodejs.org/dist/latest-v10.x/docs/api/stream.html" rel="nofollow noreferrer">https://nodejs.org/dist/latest-v10.x/docs/api/stream.html</a>. aws-sdk S3 api: <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property</a></p>
  
  <p>In sum, I am unsure what is wrong with my implementation and if using streams is a viable way to accomplish the task I am trying to perform.</p>