Unpacks a file in place.
@param {string} filename File name
@param {function(?Error)} callback
@param {function(Object)=} entryCallback
187104
function unpack(filename, callback, entryCallback) {
    var input = fs.createReadStream(filename, { flags: 'r', encoding: null }),
        files = {},
        dir = path.dirname(filename),
        returned = false,
        to = null;

    // Finishs the unpack if all files are done
    function maybeFinish() {
        if (to !== null) clearTimeout(to);
        to = setTimeout(function() {
            var alldone = true;
            var names = Object.keys(files);
            for (var i=0; i<names.length; i++) {
                if (!files[names[i]]["done"]) {
                    alldone = false;
                    break;
                }
            }
            if (alldone && !returned) {
                returned = true;
                callback(null);
            }
        }, 1000);
    }

    input.pipe(zlib.createGunzip()).pipe(tar.Parse()).on("entry", function(entry) {
        if (entryCallback) entryCallback(entry);
        if (entry["type"] == 'File') {
            files[entry["path"]] = fs.createWriteStream(path.join(dir, entry["path"]), { flags: 'w', encoding: null });
            entry.pipe(files[entry["path"]]);
            entry.on("end", function() {
                files[entry["path"]].end();
                files[entry["path"]]["done"] = true;
                maybeFinish();
            });
        } else if (entry["type"] == "Directory") {
            try {
                fs.mkdirSync(path.join(dir, entry["path"]));
            } catch (e) {
                if (!fs.existsSync(path.join(dir, entry["path"]))) {
                    if (!returned) {
                        returned = true;
                        callback(e);
                    }
                }
            }
        }
    }).on("error", function(e) {
        if (!returned) {
            returned = true;
            callback(e);
        }
    });
}
824950
public static byte[] unpackEntry(InputStream is, String name) {
    ByteArrayUnpacker action = new ByteArrayUnpacker();
    if (!handle(is, name, action))
      return null; // entry not found
    return action.getBytes();
  }
1168757
function(seriesCallback) {
      async.forEach(YAMLfiles,
        function(file, fileCallback) {
          logger.debug('Loading data from %s', file);
          var readfile;
          try {
            // read the content of the files into memory and parse as JSON
            readfile = YAML.load(fs.readFileSync(file, 'utf8'));

          } catch (e) {
            fileCallback(e);
            return;
          }
          var model = {};
          var entry = {};
          // looks like a product
          if (readfile.product) {
            logger.debug('product found: skipping');
          }
          // looks like an API
          if (readfile.swagger) {
            entry.id = createAPIID(readfile);
            entry.document = expandAPIData(readfile, dir);
            if (entry.document) {
              model.name = 'api';
              if (entry.document.info['x-ibm-name']) {
                apis[entry.document.info['x-ibm-name']] = entry.document;
              } else {
                apis[entry.document.info['title']] = entry.document;
              }
            }
          }

          if (model.name) {
            // no catalog
            entry.catalog = {};
            entry['snapshot-id'] = uid;
            app.models[model.name].create(
              entry,
              function(err, mymodel) {
                if (err) {
                  logger.error(err);
                  fileCallback(err);
                  return;
                }
                logger.debug('%s created: %j', model.name, mymodel);
                fileCallback();
              });
          } else {
            fileCallback();
          }
        },
        function(err) {
          if (err) { /* suppress eslint handle-callback-err */ }
        }
      );
      seriesCallback();
    }
630138
function openFile(filename) {
  return new Promise((resolve, reject) => {
    opener(filename, null, err => err === null ? resolve(filename) : reject(err));
  });
}
1327769
function (callback) {
					if (!handlebarsMatcher.test(file)) {
						return callback();
					}

					render(file, metadata, function (err, res) {
						if (err) return callback(err);
						// safety check to prevent file deletion in case filename doesn't change
						if (file === res) return callback();
						// safety check to prevent overwriting another file
						if (files[res]) return callback(`Cannot rename file ${file} to ${res}. A file with that name already exists.`);

						// add entry for interpolated file name
						files[res] = files[file];
						// delete entry for template file name
						delete files[file];
						callback();
					});
				}
564063
function unzip(file, callback) {
    var metafile = metapath(file);
    // return cached result of unzipped file
    // intentionally sync here to avoid race condition unzipping
    // same file for multiple layers
    try {
        var meta_data = fs.readFileSync(metafile);
        if (meta_data) {
            var meta = JSON.parse(meta_data);
            var dest_file = meta['unzipped_file'];
            if (dest_file && existsSync(dest_file)) {
                if (env == 'development') console.error('[millstone] found previously unzipped file: ' + dest_file);
                return callback(null,dest_file);
            }
        } else {
            if (env == 'development') console.error('[millstone] empty meta file for zipfile: ' + metafile);
        }
    }
    catch (err) {
        if (env == 'development') console.error('[millstone] error opening meta file for zipfile: ' + err.message);
    }
    var zf;
    try {
        zf = new zipfile.ZipFile(file);
    } catch (err) {
        return callback(err);
    }

    if (zf.names.length < 1) {
        return callback(new Error("could not find any valid data in zip archive: '" + file + "'"));
    }

    var remain = zf.names.length;
    var ds_files = _(zf.names).chain()
        .reject(function(name) {
            return (name && (name[0] === '.' || path.basename(name)[0] === '.'));
        })
        .map(function(name) {
            if (!valid_ds_extensions[path.extname(name).toLowerCase()]) return;
            var new_name = path.join(
                path.dirname(file),
                path.basename(file, path.extname(file)) +
                path.extname(name).toLowerCase());
            return {new_name:new_name,original_name:name};
        })
        .uniq()
        .compact()
        .value();

    if (!ds_files || ds_files.length < 1) return callback(new Error("Valid datasource not detected (by extension) in zip: '" + file + "'"));

    var original_name = ds_files[0].original_name;
    var new_name = ds_files[0].new_name;

    var len = Object.keys(ds_files).length;
    if (len > 1) {
        // prefer first .shp
        for (var i=0;i<len;++i) {
            var fname = ds_files[i].original_name;
            if (path.extname(fname) == '.shp') {
                original_name = fname;
                new_name = ds_files[i].new_name;
                break;
            }
        }
        if (env == 'development') {
            console.warn('[millstone] warning: detected more than one file in zip (by ext) that may be valid: ');
            for (var i=0;i<len;++i) {
                console.warn('[millstone]   ' + ds_files[i].original_name);
            }
            console.warn('[millstone] picked: ' + original_name);
        }
    }

    if (!new_name) return callback(new Error("Valid datasource not detected (by extension) in zip: '" + file + "'"));

    if (env == 'development') {
        console.warn('[millstone] renaming ' + original_name + ' to ' + new_name);
    }

    // only unzip files that match our target name
    // naive '(name.indexOf(search_basename) < 0)' does the trick
    // yes this is simplistic, but its better than corrupt data: https://github.com/mapbox/millstone/issues/99
    var search_basename = path.basename(original_name,path.extname(original_name));
    zf.names.forEach(function(name) {
        // Skip directories, hiddens.
        var basename = path.basename(name);
        if (!path.extname(name) || (name.indexOf(search_basename) < 0) || name[0] === '.' || basename[0] === '.') {
            remain--;
            if (!remain) callback(null, new_name);
        } else {
            // We're brutal in our expectations -- don't support nested
            // directories, and rename any file from `arbitraryName.SHP`
            // to `[hash].shp`.
            var dest = path.join(
                path.dirname(file),
                path.basename(file, path.extname(file)) +
                path.extname(name).toLowerCase()
            );
            zf.copyFile(name, dest, function(err) {
                if (err) return callback(err);
                remain--;
                if (!remain) {
                    add_item_to_metafile(metafile,'unzipped_file',new_name,function(err) {
                        // ignore error from add_item_to_metafile
                        //if (err && env == 'development') console.error('[millstone] ' + err.message);
                        if (err) throw err;
                        callback(null, new_name);
                    });
                }
            });
        }
    });
}
66024
function(callback) {
			fs.stat(outputFile,function(err,stat) {
				if (err) { return callback(null) }
				console.log('Found old ' + outputFile + ' so now removing')
				fs.unlinkSync(outputFile)
        return callback(null)
			})
		}
223859
function(filenames) {
				var isIn = _.some(filenames, function(line) {
					return file.path.indexOf(line) !== -1;
				});
				if (isIn) {
					self.push(file);
				}
				callback();
			}
369122
function(fileEntry) {
              var filename = fileObj.fileName.substring(0, fileObj.fileName.lastIndexOf('.'));
              var ext = fileObj.fileName.substring(fileObj.fileName.lastIndexOf('.'));
              var randomStr = randomString(); // if the file with fileName already exists, append the new filename with _randomStr ...
              fileObj.fileName = filename + '_' + randomStr + ext; // ... and file extension
              resolve({root:root, fileObj: fileObj});
            }
1093394
function iterator(filename, callback) {
    
    async.forEach(
      
        filters
      
      , function(filter, callback) {
          
          var test
            , regexp
            , matches
            
            , continuation  = filter[1]
            
            , file_path     = path.join(dir_path, filename)
            , emitter
            ;
          
          if (typeof filter[0] === 'string') {
            
            regexp = new RegExp('^' + filter[0] + '$');
            matches = regexp.exec(filename);
            
            checkAndContinue(null, matches);
            
          } else if (filter[0] instanceof RegExp) {
            
            regexp  = filter[0];
            matches = regexp.exec(filename);
            checkAndContinue(null, matches);
            
          } else {
            
            test = filter[0]
            test(filename, file_path, checkAndContinue);
            
          }
          
          function checkAndContinue(err, matches) {
            
            if (err) {
             
              callback(err);
            
            } else if (matches) {
              
              emitter = new FileEventEmitter(file_path);
              
              continuation(emitter, matches, callback);
              
            } else {
              
              callback(null);
              
            }
          
          }
        
        }
        
      , callback
    );
    
  }
756935
function handleGetFile(file, text) {
    var next = fileCallBacks[file];
    if (next) {
        try {
            next(null, text);
        } catch (e) {
            _reportError(e, file);
        }
    }
    delete fileCallBacks[file];
}
557835
function _filesToFile (files, target, separator, callback) {

			if ("undefined" === typeof files) {
				throw new ReferenceError("missing \"files\" argument");
			}
				else if ("object" !== typeof files || !(files instanceof Array)) {
					throw new TypeError("\"files\" argument is not an Array");
				}
			else if ("undefined" === typeof target) {
				throw new ReferenceError("missing \"target\" argument");
			}
				else if ("string" !== typeof target) {
					throw new TypeError("\"target\" argument is not a string");
				}
			else if ("undefined" === typeof callback && "undefined" === typeof separator) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof separator) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				const _target = target.trim();

				if ("" === _target) {
					throw new Error("\"target\" argument is empty");
				}
				else {

					const _callback = "undefined" === typeof callback ? separator : callback;

					Promise.resolve().then(() => {
						return isFileProm(_target);
					}).then((exists) => {

						return !exists ? Promise.resolve() : new Promise((resolve, reject) => {

							fs.unlink(_target, (err) => {
								return err ? reject(err) : resolve();
							});

						});

					}).then(() => {

						if (!files.length) {

							return new Promise((resolve, reject) => {

								fs.writeFile(_target, "", (err) => {
									return err ? reject(err) : resolve();
								});

							});

						}
						else {

							return filesToStreamProm(files, "string" === typeof separator ? separator : " ").then((readStream) => {

								return new Promise((resolve, reject) => {

									let error = false;
									readStream.once("error", (_err) => {
										error = true; reject(_err);
									}).pipe(fs.createWriteStream(_target, { "flags": "a" }).once("error", (_err) => {
										error = true; reject(_err);
									}).once("close", () => {

										if (!error) {
											resolve();
										}

									}));

								});

							});

						}

					}).then(() => {
						_callback(null);
					}).catch(_callback);

				}

			}

		}
178982
function load(filename) {

  return function(cb) {
    var file = path.join(process.cwd(), filename)
      , json = require(file)
      , model = exports[json.table]
      , rows = json.rows;

    console.log('Loading', file);

    run();
    function run() {
      var row = rows.shift();
      if(row !== undefined) {
        model.create(row, function(err) {
          if(err) {
            cb(err);
          } else {
            run();
          }
        });
      } else {
        cb();
      }
    }
  };
}
172065
function (readCallback, compile, args) {
    if (readCallback === undefined) {
      readCallback = function (path) {
        return {
          error: 'File import callback not supported'
        };
      };
    }

    // This is to support multiple versions of Emscripten.
    var addFunction = soljson.addFunction || soljson.Runtime.addFunction;
    var removeFunction = soljson.removeFunction || soljson.Runtime.removeFunction;

    var cb = addFunction(wrapCallback(readCallback));
    var output;
    try {
      args.push(cb);
      output = compile.apply(undefined, args);
    } catch (e) {
      removeFunction(cb);
      throw e;
    }
    removeFunction(cb);
    return output;
  }
99799
function unZipFile(zipFileName) {
  yauzl.open(zipFileName, {
    lazyEntries: true
  }, function (err, zipFile) {
    if (err) {
      throw err
    }
    zipFile.readEntry()
    zipFile.on('entry', function (entry) {
      if (targetEntry === entry.fileName) {
        mkdirp.sync(writeFolder)
        zipFile.openReadStream(entry, function (errInReadStream, readStream) {
          if (errInReadStream) {
            throw errInReadStream
          }
          readStream.pipe(fs.createWriteStream(binPath))
          readStream.on('end', function () {
            zipFile.readEntry()
            console.log('unzip completed ' + binPath)
            fs.chmodSync(binPath, '755')
            console.log('chmod 755')
          })
        })
      } else {
        zipFile.readEntry()
      }
    })
  })
}
668820
function readFiles (filepaths, callback) {
  async.map(filepaths, readFile.bind(this), function (err, files) {

    if (err) callback(err);

    callback(null, files);
  });
}
525578
function( key /* or array */, callback ) {
            var me = this;
            if ( this.isArray( key ) ) {
                var values = [];
                for ( var i = 0, il = key.length; i < il; i++ ) {
                    me.get( key[i], function( result ) {
                        if ( result ) values.push( result );
                        if ( values.length === il && callback ) {
                            me.lambda( callback ).call( me, values );
                        }
                    });
                }
            } else {
                var error = function(e) { fail( e ); if ( callback ) me.lambda( callback ).call( me ); };
                root( this, function( store ) {
                    store.getFile( key, {create:false}, function( entry ) {
                        entry.file(function( file ) {
                            var reader = new FileReader();

                            reader.onerror = error;

                            reader.onload = function(e) {
                                if ( callback ) me.lambda( callback ).call( me, JSON.parse( e.target.result ) );
                            };

                            reader.readAsText( file );
                        }, error );
                    }, error );
                });
            }
            return this;
        }