简体   繁体   English

如何修改node.js流

[英]How to modify node.js stream

I am streaming an xml file from S3. 我正在从S3流式传输xml文件。 I need to build a new xml file with a different structure for sphinx search engine. 我需要为狮身人面像搜索引擎构建具有不同结构的新xml文件。 I am already streaming the file from S3, piping it into my SAX parser but now I need to figure out how I can make modifications to the stream (after the SAX parser) and upload to S3. 我已经在从S3流式传输文件,并将其通过管道传输到我的SAX解析器中,但是现在我需要弄清楚如何对流进行修改(在SAX解析器之后)并上传到S3。

parser.on('startElement', function(name, attrs) {
    // Do something
});

I found what seems to be a great S3 library that streams called knox , so I am currently using that library. 我发现似乎是一个很棒的S3库,它可以流传输称为knox的流,因此我目前正在使用该库。 I'm not stuck on this library, just what I found that seems to be decent. 我没有被这个库困扰,只是我发现它看起来不错。 The code that they have to stream data to S3 in the example, is only from an HTTP request. 在示例中,他们必须将数据流传输到S3的代码仅来自HTTP请求。 I am relatively new to streams, since I have a PHP background. 我对流技术比较陌生,因为我有PHP背景。

Knox Example Stream: 诺克斯示例流:

http.get('http://google.com/doodle.png', function(res){
  var headers = {
      'Content-Length': res.headers['content-length']
    , 'Content-Type': res.headers['content-type']
  };
  client.putStream(res, '/doodle.png', headers, function(err, res){
    // Logic
  });
});

I am thinking I would need to do something on the lines of this. 我想我需要做一些类似的事情。

parser.on('startElement', function(name, attrs) {

  var headers = {
      'Content-Length': res.headers['content-length']
    , 'Content-Type': res.headers['content-type']
  };
  client.putStream(res, '/doodle.png', headers, function(err, res){
    // Logic
  });

});

Any help is greatly appreciated. 任何帮助是极大的赞赏。 Thanks. 谢谢。

This discussion of Node's new streams speaks explicitly about transforming streams from S3. 对Node的新流的讨论明确地谈到了从S3转换流。

NB: This is in reference to streams as implemented in Node 0.10.x 注意:这是指在节点0.10.x中实现的流

https://www.npmjs.org/package/through https://www.npmjs.org/package/through

This module will do what you need. 该模块将满足您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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