lib/millstone.js
function localize(url, options, callback) {
    existsAsync(options.filepath, function(exists) {
        if (exists) {
            var re_download = false;
            // unideal workaround for frequently corrupt/partially downloaded zips
            // https://github.com/mapbox/millstone/issues/85
            if (path.extname(options.filepath) == '.zip') {
                try {
                  var zf = new zipfile.ZipFile(options.filepath);
                  if (zf.names.length < 1) {
                      throw new Error("could not find any valid data in zip archive: '" + options.filepath + "'");
                  }
                } catch (e) {
                    if (env == 'development') console.error('[millstone] could not open zip archive: "' + options.filepath + '" attempting to re-download from "'+url+"'");
                    re_download = true;
                }
            }
            if (!re_download) {
                return callback(null, options.filepath);
            }
        }
        var dir_path = path.dirname(options.filepath);
        mkdirp(dir_path, 0755, function(err) {
            if (err && err.code !== 'EEXIST') {
                if (env == 'development') console.error('[millstone] could not create directory: ' + dir_path);
                callback(err);
            } else {
                download(url, options, function(err, filepath) {
                    if (err) return callback(err);
                    callback(null, filepath);
                });
            }
        });
    });
}
function localize(url, options, callback) {
    existsAsync(options.filepath, function(exists) {
        if (exists) {
            var re_download = false;
            // unideal workaround for frequently corrupt/partially downloaded zips
            // https://github.com/mapbox/millstone/issues/85
            if (path.extname(options.filepath) == '.zip') {
                try {
                  var zf = new zipfile.ZipFile(options.filepath);
                  if (zf.names.length < 1) {
                      throw new Error("could not find any valid data in zip archive: '" + options.filepath + "'");
                  }
                } catch (e) {
                    if (env == 'development') console.error('[millstone] could not open zip archive: "' + options.filepath + '" attempting to re-download from "'+url+"'");
                    re_download = true;
                }
            }
            if (!re_download) {
                return callback(null, options.filepath);
            }
        }
        var dir_path = path.dirname(options.filepath);
        mkdirp(dir_path, 0755, function(err) {
            if (err && err.code !== 'EEXIST') {
                if (env == 'development') console.error('[millstone] could not create directory: ' + dir_path);
                callback(err);
            } else {
                download(url, options, function(err, filepath) {
                    if (err) return callback(err);
                    callback(null, filepath);
                });
            }
        });
    });
}
function localize ( url , options , callback ) { existsAsync ( options . filepath , function ( exists ) { if ( exists ) { var re_download = false ; // unideal workaround for frequently corrupt/partially downloaded zips // https://github.com/mapbox/millstone/issues/85 if ( path . extname ( options . filepath ) == '.zip' ) { try { var zf = new zipfile . ZipFile ( options . filepath ) ; if ( zf . names . length < 1 ) { throw new Error ( "could not find any valid data in zip archive: '" + options . filepath + "'" ) ; } } catch ( e ) { if ( env == 'development' ) console . error ( '[millstone] could not open zip archive: "' + options . filepath + '" attempting to re-download from "' + url + "'" ) ; re_download = true ; } } if ( ! re_download ) { return callback ( null , options . filepath ) ; } } var dir_path = path . dirname ( options . filepath ) ; mkdirp ( dir_path , 0755 , function ( err ) { if ( err && err . code !== 'EEXIST' ) { if ( env == 'development' ) console . error ( '[millstone] could not create directory: ' + dir_path ) ; callback ( err ) ; } else { download ( url , options , function ( err , filepath ) { if ( err ) return callback ( err ) ; callback ( null , filepath ) ; } ) ; } } ) ; } ) ; }
Retrieve a remote copy of a resource only if we don't already have it.
Retrieve a remote copy of a resource only if we don t already have it .