tasks/download.js
function (info, cb) {
            // Default to a binary request
            var options = info.src;
            var dest = info.dest;

            // Request the url
            var req = request(options);

            // On error, callback
            req.on('error', cb);

            // On response, callback for writing out the stream
            req.on('response', function handleResponse (res) {
                // Assert the statusCode was good
                var statusCode = res.statusCode;
                if (statusCode < 200 || statusCode >= 300) {
                  return cb(new Error('Fetching ' + JSON.stringify(options) + ' failed with HTTP status code ' + statusCode));
                }

                // Otherwise, write out the content
                var destdir = path.dirname(dest);
                grunt.file.mkdir(destdir);
                var writeStream = fs.createWriteStream(dest);
                // Use `req` as the source of data https://github.com/request/request/blob/v2.51.1/request.js#L1255-L1267
                // DEV: This is to pipe out gunzipped data
                var dataStream = req;
                dataStream.pipe(writeStream);

                // When the stream errors or completes, exit
                writeStream.on('error', cb);
                writeStream.on('close', cb);
            });
        }
function (info, cb) {
            // Default to a binary request
            var options = info.src;
            var dest = info.dest;

            // Request the url
            var req = request(options);

            // On error, callback
            req.on('error', cb);

            // On response, callback for writing out the stream
            req.on('response', function handleResponse (res) {
                // Assert the statusCode was good
                var statusCode = res.statusCode;
                if (statusCode < 200 || statusCode >= 300) {
                  return cb(new Error('Fetching ' + JSON.stringify(options) + ' failed with HTTP status code ' + statusCode));
                }

                // Otherwise, write out the content
                var destdir = path.dirname(dest);
                grunt.file.mkdir(destdir);
                var writeStream = fs.createWriteStream(dest);
                // Use `req` as the source of data https://github.com/request/request/blob/v2.51.1/request.js#L1255-L1267
                // DEV: This is to pipe out gunzipped data
                var dataStream = req;
                dataStream.pipe(writeStream);

                // When the stream errors or completes, exit
                writeStream.on('error', cb);
                writeStream.on('close', cb);
            });
        }
function ( info , cb ) { // Default to a binary request var options = info . src ; var dest = info . dest ; // Request the url var req = request ( options ) ; // On error, callback req . on ( 'error' , cb ) ; // On response, callback for writing out the stream req . on ( 'response' , function handleResponse ( res ) { // Assert the statusCode was good var statusCode = res . statusCode ; if ( statusCode < 200 || statusCode >= 300 ) { return cb ( new Error ( 'Fetching ' + JSON . stringify ( options ) + ' failed with HTTP status code ' + statusCode ) ) ; } // Otherwise, write out the content var destdir = path . dirname ( dest ) ; grunt . file . mkdir ( destdir ) ; var writeStream = fs . createWriteStream ( dest ) ; // Use `req` as the source of data https://github.com/request/request/blob/v2.51.1/request.js#L1255-L1267 // DEV: This is to pipe out gunzipped data var dataStream = req ; dataStream . pipe ( writeStream ) ; // When the stream errors or completes, exit writeStream . on ( 'error' , cb ) ; writeStream . on ( 'close' , cb ) ; } ) ; }
Downloads single file to local computer.
Downloads single file to local computer .