Mitar
Mitar

Reputation: 7030

How to pass a node.js Buffer to a function which expects a Stream?

I have a Buffer with tar contents and I would like to parse this with tar node.js package, but all examples of use of this package are using .pipe() and streams - how can I pass buffer to tar package?

I get Buffer from AWS SDK.

Upvotes: 0

Views: 707

Answers (1)

loganfsmyth
loganfsmyth

Reputation: 161477

Streams have a standard API, so you can just use write and end directly instead of using pipe.

var data = ... // Buffer
var parser = tar.Parse();

// Bind whatever handlers you would normally bind
parser.on('entry', function(e){
});

// Write the data into the parser, which will parse it and trigger your event handlers
parser.end(data);

Upvotes: 1

Related Questions