code: function writeStream(filename, st) {
      var d = Q.defer();
  
      var wstream = fs.createWriteStream(filename);
  
      wstream.on('finish', function () {
          d.resolve();
      });
      wstream.on('error', function (err) {
          d.reject(err);
      });
  
      st.on('error', function(err) {
          d.reject(err);
      });
  
      st.pipe(wstream);
  
      return d.promise;
  }
docs: Write a stream to a file