Skip to content

How do I prepend a stream to another? #255

Description

@wyuenho

Hi!

I'm still getting used to gulp's processing model and it's not entirely clear to me how to achieve something like this:

src1 | filter concat src2 | filter > output

The recipe here results in an unordered stream, but I'd like concat to be really concat and not just merge chucks arbitrarily.

Thanks!

Activity

  1. darsain commented on Feb 8, 2014

    @darsain
    Contributor

    You can use streamqueue for that. The problem is that gulp is outputting old streams and streamqueue had to go through quite some hackery to work with it, loosing some of the efficiency of streams in the process :/

    Example:

    fixed example below

  2. wyuenho commented on Feb 8, 2014

    @wyuenho
    Author

    Doesn't work. streamqueue only works with string/buffer chunks.

  3. darsain commented on Feb 8, 2014

    @darsain
    Contributor

    Shit. I forgot an option flag :) You need to specify { objectMode: true }:

    var gulp = require('gulp');
    var concat = require('gulp-concat');
    var streamqueue = require('streamqueue');
    
    gulp.task('default', function () {
        return streamqueue({ objectMode: true },
            gulp.src('foo/*'),
            gulp.src('bar/*')
        )
            .pipe(concat('result.txt'))
            .pipe(gulp.dest('build'));
    });
    
    // ... or ...
    
    gulp.task('default', function () {
        var stream = streamqueue({ objectMode: true });
        stream.queue(gulp.src('foo/*'));
        stream.queue(gulp.src('bar/*'));
        return stream.done()
            .pipe(concat('result.txt'))
            .pipe(gulp.dest('build'));
    });
  4. wyuenho commented on Feb 8, 2014

    @wyuenho
    Author

    Ok cool it works now thanks!

    I was wondering, I think the trick here is I need to buffer the first stream, and then append the data from the second stream to the buffer, how might I do that if were not to use any other libraries?

  5. yocontra commented on Feb 8, 2014

    @yocontra
    Member
  6. yocontra commented on Feb 11, 2014

    @yocontra
    Member

    Closing this since it seems like the problem is solved

  7. nickjanssen commented on Aug 28, 2014

    @nickjanssen

    Thanks @darsain working great!

  8. chrismarx commented on Feb 11, 2016

    @chrismarx

    +1 for objectMode, that's critical!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions