BlobDownloadService.prototype.downloadContainer = function()

in Artifacts/linux-deploy-app-from-storage/BlobDownloadService.js [84:123]


BlobDownloadService.prototype.downloadContainer = function (container, destination, callback) {
    var self = this;

    self._blobSvc.listBlobsSegmented(container, null, this._options, function (err, result, response) {
        self._aggregateBlobs(err, result, function (err, blobs) {
            if (err) {
                callback(err, null);
            }

            var blobCount = blobs.length;
            var blobsDownloaded = 0;

            for (var i = 0; i < blobCount; i += 1) {
                var blobName = blobs[i].name;
                var filePath = destination + '/' + blobName;

                mkdirp.sync(path.dirname(filePath));
                console.log(blobName + ' -> ' + filePath);

                self._blobSvc.getBlobToLocalFile(
                    container,
                    blobName,
                    filePath,
                    function (err, serverBlob) {
                        blobsDownloaded += 1;
                        self._blobs.push(serverBlob);

                        if (err) {
                            callback(err, null);
                        }
                        else if ((result.continuationToken === null) && (blobsDownloaded >= blobCount)) {
                            // No further pages to download, all blobs in the current page have been accounted for
                            // Time to wrap up and call the caller back.
                            callback(null, self._blobs);
                        }
                    });
            }
        });
    });
};