简体   繁体   中英

Stream.pipe() to a variable in node.js

Just starting out with Node, and I am running into a small hiccup: I am trying to write the output from a stream to a variable in my code. However, it seems that only STDOUT will work. Is it possible to pipe the output to a string? Many thanks

var userData = null;

s3.GetObject(getOptions, { stream : true }, function(err, data) {
    fmt.dump(err, 'err');
    fmt.dump(data, 'data');

   // stream the file to a var

    fmt.sep();
    fmt.title('User data file:');
    data.Stream.pipe(userData);
    data.Stream.on('end', function() {
        fmt.sep();
    });
});

This code throws the following error:

_stream_readable.js:476 dest.on('unpipe', onunpipe); ^ TypeError: Cannot call method 'on' of null

如果您的userData = null,则将引发错误,它需要数据

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM