lib/main.js
function(languageSlug, projectSlug, resourceSlug, progressCallback) {
        // support passing args as an object
        if(languageSlug != null && typeof languageSlug == 'object') {
            resourceSlug = languageSlug.resourceSlug;
            projectSlug = languageSlug.projectSlug;
            languageSlug = languageSlug.languageSlug;
        }

        let destFile;
        let tempFile;
        let containerDir;
        return new Promise(function(resolve, reject) {
                try {
                    resolve(library.public_getters.getResource(languageSlug, projectSlug, resourceSlug));
                } catch(err) {
                    reject(err);
                }
            })
            .then(function(resource) {
                if(!resource) return Promise.reject(new Error('Unknown resource'));
                let containerFormat = getResourceContainerFormat(resource.formats);
                if(!containerFormat) return Promise.reject(new Error('Missing resource container format'));
                let containerSlug = rc.tools.makeSlug(languageSlug, projectSlug, resourceSlug);
                containerDir = path.join(resourceDir, containerSlug);
                destFile = containerDir + '.' + rc.tools.spec.file_ext;
                tempFile = containerDir + '.download';

                rimraf.sync(tempFile);

                mkdirp(path.dirname(containerDir));
                if(!containerFormat.url) return Promise.reject('Missing resource format url');
                return request.download(containerFormat.url, tempFile, progressCallback);
            })
            .then(function(response) {
                if(response.status !== 200) {
                    rimraf.sync(tempFile);
                    return Promise.reject(response);
                }
                // replace old files
                rimraf.sync(containerDir);
                return new Promise(function(resolve, reject) {
                    mv(tempFile, destFile, {clobber: true}, function(err) {
                        if(err) {
                            reject(err);
                        } else {
                            resolve(destFile);
                        }
                    });
                });
            });
    }
function(languageSlug, projectSlug, resourceSlug, progressCallback) {
        // support passing args as an object
        if(languageSlug != null && typeof languageSlug == 'object') {
            resourceSlug = languageSlug.resourceSlug;
            projectSlug = languageSlug.projectSlug;
            languageSlug = languageSlug.languageSlug;
        }

        let destFile;
        let tempFile;
        let containerDir;
        return new Promise(function(resolve, reject) {
                try {
                    resolve(library.public_getters.getResource(languageSlug, projectSlug, resourceSlug));
                } catch(err) {
                    reject(err);
                }
            })
            .then(function(resource) {
                if(!resource) return Promise.reject(new Error('Unknown resource'));
                let containerFormat = getResourceContainerFormat(resource.formats);
                if(!containerFormat) return Promise.reject(new Error('Missing resource container format'));
                let containerSlug = rc.tools.makeSlug(languageSlug, projectSlug, resourceSlug);
                containerDir = path.join(resourceDir, containerSlug);
                destFile = containerDir + '.' + rc.tools.spec.file_ext;
                tempFile = containerDir + '.download';

                rimraf.sync(tempFile);

                mkdirp(path.dirname(containerDir));
                if(!containerFormat.url) return Promise.reject('Missing resource format url');
                return request.download(containerFormat.url, tempFile, progressCallback);
            })
            .then(function(response) {
                if(response.status !== 200) {
                    rimraf.sync(tempFile);
                    return Promise.reject(response);
                }
                // replace old files
                rimraf.sync(containerDir);
                return new Promise(function(resolve, reject) {
                    mv(tempFile, destFile, {clobber: true}, function(err) {
                        if(err) {
                            reject(err);
                        } else {
                            resolve(destFile);
                        }
                    });
                });
            });
    }
function ( languageSlug , projectSlug , resourceSlug , progressCallback ) { // support passing args as an object if ( languageSlug != null && typeof languageSlug == 'object' ) { resourceSlug = languageSlug . resourceSlug ; projectSlug = languageSlug . projectSlug ; languageSlug = languageSlug . languageSlug ; } let destFile ; let tempFile ; let containerDir ; return new Promise ( function ( resolve , reject ) { try { resolve ( library . public_getters . getResource ( languageSlug , projectSlug , resourceSlug ) ) ; } catch ( err ) { reject ( err ) ; } } ) . then ( function ( resource ) { if ( ! resource ) return Promise . reject ( new Error ( 'Unknown resource' ) ) ; let containerFormat = getResourceContainerFormat ( resource . formats ) ; if ( ! containerFormat ) return Promise . reject ( new Error ( 'Missing resource container format' ) ) ; let containerSlug = rc . tools . makeSlug ( languageSlug , projectSlug , resourceSlug ) ; containerDir = path . join ( resourceDir , containerSlug ) ; destFile = containerDir + '.' + rc . tools . spec . file_ext ; tempFile = containerDir + '.download' ; rimraf . sync ( tempFile ) ; mkdirp ( path . dirname ( containerDir ) ) ; if ( ! containerFormat . url ) return Promise . reject ( 'Missing resource format url' ) ; return request . download ( containerFormat . url , tempFile , progressCallback ) ; } ) . then ( function ( response ) { if ( response . status !== 200 ) { rimraf . sync ( tempFile ) ; return Promise . reject ( response ) ; } // replace old files rimraf . sync ( containerDir ) ; return new Promise ( function ( resolve , reject ) { mv ( tempFile , destFile , { clobber : true } , function ( err ) { if ( err ) { reject ( err ) ; } else { resolve ( destFile ) ; } } ) ; } ) ; } ) ; }
Downloads a resource container.
This expects a correctly formatted resource container
and will download it directly to the disk

Note: You may provide a single object parameter if you prefer

once the api can deliver proper resource containers this method
should be renamed to downloadContainer

@param languageSlug {string}
@param projectSlug {string}
@param resourceSlug {string}
@param progressCallback {function} receives download progress updates
@returns {Promise.<String>} the path to the downloaded resource container
Downloads a resource container . This expects a correctly formatted resource container and will download it directly to the disk