gulp.pipe() - How do I read a chunk?

618 views
Skip to first unread message

Ken Snyder

unread,
Jan 18, 2015, 5:10:19 PM1/18/15
to uta...@googlegroups.com
I'm trying to read data passed to a gulp.pipe() callback. I can't figure out how to get the data as a string.

See this gist or look below.

Thanks,

Ken Snyder


gulp.task('hello', function() {
    return gulp.src([
        'hello.js'
    ])
    .pipe(uglify())
    .pipe(
        through2.obj(function(chunk, enc, callback) {
            // I want the minified contents of hello.js
            // chunk.isBuffer() -> true
            // chunk.toString(enc) -> [object Object]
            // console.log(chunk) ->
            //    <File "hello.js" <Buffer ...>>
        })
    );
});

Rich Snapp

unread,
Jan 18, 2015, 5:55:12 PM1/18/15
to uta...@googlegroups.com
The chunk comes through as a vinyl object https://github.com/wearefractal/vinyl

To get the contents you'll need to use chunk.contents.toString(enc).

-Rich

Ken Snyder

unread,
Jan 18, 2015, 6:20:09 PM1/18/15
to uta...@googlegroups.com
Perfect. Thanks Rich!

--
Group meets on the 1st Thursday and 3rd Tuesday of each month. See http://utahjs.com/location/ for more info.
---
You received this message because you are subscribed to the Google Groups "Utah JavaScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to utahjs+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/utahjs.

Reply all
Reply to author
Forward
0 new messages