title: Understanding node streams and vinyl-fs
body: <p>I'm having a weird issue, and I'm not sure where my problem is. Probably it's because I lack understanding of some basics of node streams or vinyl-fs.</p>
  
  <p>Anyway, here is the description:</p>
  
  <p>I'm building different scripts that I would like to use with gulp. </p>
  
  <p>This one, for instance, is building some assets I need; more precisely, I'm copying bootstrap source files from node_modules to my assets folder.</p>
  
  <p>This function should return a promise, this way I can use it with gulp more easily.</p>
  
  <p>This is the sass-bootstrap.js file that will do the job:</p>
  
  <ul>
  <li>this is a shorter version, there are some checks before, but not related with my question.</li>
  <li>assume all variables defined.</li>
  </ul>
  
  
  
  <pre><code>var defer    = Q.defer(),
      vinylFs  = require( 'vinyl-fs' ),
      map      = require( 'map-stream' );
  
  function sass_bootstrap() {
    var defer = Q.defer();
    vinylFs.src( [ bootstrap_sass_route + '/**/_*.scss' ] )
      .pipe( vinylFs.dest( assets_sass_bootstrap ) )
      .pipe( map( function( file, cb ) { 
        cb( null, file ); 
      }))
      .on( 'end', function(){
        defer.resolve();
      });
    return defer.promise;
  }
  </code></pre>
  
  <p>And this is the gulp task that use it:</p>
  
  <ul>
  <li>again its a simplified version, whith just the relevant code included</li>
  </ul>
  
  
  
  <pre><code>gulp.task( 'development', function ( cb ) {
  
    sass_bootstrap()
      .then( function(){
        cb();
      })
      .catch( function( err ){
        err.log();
        cb();
      });
  
  
  });
  </code></pre>
  
  <p>This is working good, but I don't quite understand why it doesn't work this way:</p>
  
  <pre><code>function sass_bootstrap() {
    var defer = Q.defer();
    vinylFs.src( [ bootstrap_sass_route + '/**/_*.scss' ] )
      .pipe( vinylFs.dest( assets_sass_bootstrap ) )
      .on( 'end', function(){
        defer.resolve();
      });
    return defer.promise;
  }
  </code></pre>
  
  <p>Furthermore, I don't understand why I need the call to <code>map()</code>. I think on my first example is really not needed at all ...</p>
  
  <p>Any hint or explanation would be very appreciated.</p>
  
  <p>Thanks!</p>