Git Product home page Git Product logo

message-stream's Introduction

CI Test Status Code Climate NPM

haraka-message-stream

Used By

  • Haraka/transaction.js
  • haraka/test-fixtures/transaction

USAGE

new MessageStream(cfg, uuid, header_list)

message-stream's People

Contributors

msimerson avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

seanpm2001

message-stream's Issues

message-stream: standardize & modernize

  • populate [files] in package.json. Delete .npmignore.
  • automated code linting. #3308
    • dep: eslint-plugin-haraka -> @haraka/eslint-config
    • update 'lint' script in package.json
    • verify 'lint' CI test config
  • lint: remove duplicate / stale rules from .eslintrc
  • automated code formatting (see also #3308)
  • automated CI testing.
    • mostly done, verify that local copy of ci.yml is up-to-date.
  • CONTRIBUTORS: see 3309
  • consistent naming of "special" files like CHANGELOG.md.
  • CHANGELOG: verify links at bottom (due to inconsistent tag naming)
    • latest .release does this, fixes most, and warns of errors it can't fix
  • verify GitHub repo About link points to npm package
  • convert test suites to mocha "style"
    • works great today and with node --test in v18+

Unable to pipe multiple times

When trying to pipe the connection.transaction.message_stream to a target stream more than once, an error is thrown.

Example code in a queue plugin (without error handling for simplicity):

// in any plugin, possibly multiple times:
var txn = connection.transaction;
['/tmp/test-a', '/tmp/test-b', '/tmp/test-c'].forEach(file =>
{
    txn.message_stream.pipe(fs.createWriteStream(file));
    txn.message_stream.pause();
}

// finally, in the queue plugin:
txn.message_stream.resume();

This throws an error "Cannot pipe while currently piping". Browsing the code, it looks like this message_stream cannot be used in place of any regular readable stream?

The first idea for a workaround would be to listen to 'data', 'error', and 'end' events, instead of using the message_stream.pipe() function. But that does not work out of the box either, I've tried multiple ways, but it only got me in a deeper mess.

Currently, I am using the following workaround instead (with error handling):

var txn = connection.transaction;
var multistream = txn.notes.message_stream || (txn.notes.message_stream = new stream.PassThrough());
['/tmp/test-a', '/tmp/test-b', '/tmp/test-c'].forEach(file =>
{
    var target = fs.createWriteStream(file);
    target.on('error', err => { throw err; });
    multistream.on('error', err => target.destroy(err));
    multistream.pipe(target);
});

await new Promise((resolve, reject) =>
{
    multistream.on('error', reject);
    multistream.on('finish', resolve);
    
    txn.message_stream.on('error', err => multistream.destroy(err));
    txn.message_stream.pipe(multistream);
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.