
Download files from aws s3 node - rather valuable
Requests With a Node.js Stream Object
You can create a request that streams the returned data directly to a Node.js object by calling the method on the request. Calling returns the raw HTTP stream managed by the request. The raw data stream can then be piped into any Node.js object.
This technique is useful for service calls that return raw data in their payload, such as calling on an Amazon S3 service object to stream data directly into a file, as shown in this example.
When you stream data from a request using , only the raw HTTP data is returned. The SDK does not post-process the data.
Because Node.js is unable to rewind most streams, if the request initially succeeds, then retry logic is disabled for the rest of the response. In the event of a socket failure while streaming, the SDK won't attempt to retry or send more data to the stream. Your application logic needs to identify such streaming failures and handle them.
Avoid using a callback to trap errors in the call, such as when the key is not valid, as this tactic results in a race condition where two requests are opened at once, but the data from both are piped to the same destination.
The solution is to attach an error event listener to the Amazon S3 stream, as shown in the following example.
-