function writeStream(filename, st) {
    var d = Promise.defer();

    var wstream = fs.createWriteStream(filename);
    var cleanup = function() {
        destroy(wstream);
        wstream.removeAllListeners();
    };

    wstream.on('finish', function () {
        cleanup();
        d.resolve();
    });
    wstream.on('error', function (err) {
        cleanup();
        d.reject(err);
    });

    st.on('error', function(err) {
        cleanup();
        d.reject(err);
    });

    st.pipe(wstream);

    return d.promise;
}
// Write a stream to a file
Write a stream to a file
Write a stream to a file
function writeStream(filename, st) {
    var d = Promise.defer();
    var wstream = fs.createWriteStream(filename);
    var cleanup = function() {
        destroy(wstream);
        wstream.removeAllListeners();
    };
    wstream.on('finish', function () {
        cleanup();
        d.resolve();
    });
    wstream.on('error', function (err) {
        cleanup();
        d.reject(err);
    });
    st.on('error', function(err) {
        cleanup();
        d.reject(err);
    });
    st.pipe(wstream);
    return d.promise;
}
function writeStream ( filename , st ) { var d = Promise . defer ( ) ; var wstream = fs . createWriteStream ( filename ) ; var cleanup = function ( ) { destroy ( wstream ) ; wstream . removeAllListeners ( ) ; } ; wstream . on ( 'finish' , function ( ) { cleanup ( ) ; d . resolve ( ) ; } ) ; wstream . on ( 'error' , function ( err ) { cleanup ( ) ; d . reject ( err ) ; } ) ; st . on ( 'error' , function ( err ) { cleanup ( ) ; d . reject ( err ) ; } ) ; st . pipe ( wstream ) ; return d . promise ; }
Write a stream to a file
Write a stream to a file