hughsk / hughsk/from2

from2 doesn't work without through2

Open
#7 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
131
Forks
20
PR merge metrics
No merged PRs in 30d

Description

I try it and get infinite loop in `headStream`

``` javascript
var headStream = from2.obj(function (size, next) {
var file = new File({
path: 'head.js',
contents: new Buffer('head content')
});
next(null, file);
})

series(headStream, otherStream)
.pipe(g.concat(name))
.pipe(gulp.dest(destPath))
```

I try it and get 16 loops (size = 16), but head file doesn't write to output file

``` javascript
var flag = false;
var headStream = from2.obj(function (size, next) {
if (flag) return this.push(null);
...
flag = true;
next(null, file);
})
...
```

If I use through it works!

``` javascript
var headStream = from2.obj(function (size, next) {
...
this.push(file)
next();
})
.pipe(through2.obj(function (file, enc, callback) {
callback(null, file);
}));
...
```

Why? And how to do it without through?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the from2.obj callback and compare the two examples in the issue, especially how the file is emitted and the stream is ended. Trace the ReadableStream behavior around headStream and verify that the single head file reaches the downstream pipeline without through2; reproduce the reported repeated calls before confirming the fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.