3

I'm working on a gulp task that want to debug some file and I want to read it in the console, for example.

It doesn't matter if it's by stream or by simple task. I try to print the content of the vinyl object... but without any good result

gulp.task('task', function(){
    console.log( gulp.src('path/to/file.txt').content.toString() );
});

or through node

function sendTo(res) {   
    return through(
        function write(data) {    // this will be called once for each file
            res.write(data.contents);
        },
        function end() {    // this will be called when there are no more files
            res.end()
        }
    );
}

gulp.task('task', function(res){
    gulp.src('path/to/file.txt')
        .pipe(sendTo(res));
});

or try to do it with fs node module with the same results...

fs.readFile('path/to/file.txt', {encoding: 'utf-8', flag: 'rs'}, function(e, data) {
  if (e) return console.log(e);
  console.log(data);
});

Any idea to print the content of the file ?

davesnx
  • 374
  • 3
  • 16

1 Answers1

1

This is the exactly problem of my other answer, the asyncronous of gulp/node try to read the file before the file could be created...

The easy form is with node (yeah, I'm right :P)

fs.readFile('path/to/file.txt', {encoding: 'utf-8', flag: 'rs'}, function(e, data) {
  if (e) return console.log(e);
  console.log(data);
});
davesnx
  • 374
  • 3
  • 16