/* istanbul ignore next: no need to test inquirer 
Ask use a few questions on command prompt
@param {function} callback callback function when file has been written
@returns {void}
190503
function promptUser(callback) {
  inquirer.prompt([
    {
      type: 'list',
      name: 'format',
      message: 'What format do you want your config file to be in?',
      default: 'JSON',
      choices: ['JSON', 'YAML']
    }
  ], function(answers) {
    var config = processAnswers(answers);
    writeFile(config, answers.format === 'JSON', callback);
  });
}
138128
function(callback) {
    const contentStream = new stream.Writable();
    const data = [];

    contentStream._write = function(chunk) {
      callback(null, chunk.toString());
    };


    // here we can add the options in the future:
    // (options, context, gitRawCommitsOpts, parserOpts, writerOpts);
    const options = {
      preset: program.changelogpreset,
      releaseCount: program.releasecount,
    };
    changelog(options)
    // Use through() to handle multiple chunks which could be returned from changelog()
        .pipe(through({
          objectMode: true,
        }, function(chunk, enc, cb) {
          try {
            data.push(chunk);
          } catch (err) {
            setImmediate(function() {
              throw err;
            });
          }

          cb();
        }, function(cb) {
        // This function is called once ALL the object-chunks have been processed.
          data.push(null);

          cb(null, data.join('')); // Pass the data to the next stream processor
        }))
        .pipe(contentStream);
  }
616245
function(callback) {
			var query = this.toQuery();
			var idx = 0;
			while (query.args.length > 0) {
				var value = query.args.shift();
				query.text = query.text.replace(/\?/,callback(value,idx));
				idx++;
			}
			return query.text;
		}
836558
function readFile(file, callback){

		// Run this sequentially
		sync(function(){
			// Create a new FileReader Object
			var reader = new FileReader();

			// Set an onload handler because we load files into it Asynchronously
			reader.onload = function(e){

				// Print onto Canvas
				callback( this.result );

				// Run the next one;
				sync();
			};

			reader.readAsDataURL(file);
		});
	}
1043908
function ask(questions, finish, answers, input, output) {
    finish = finish || function() {};
    input = input || function(cb) {process.stdin.on('data', cb);};
    output = output || function(a) {console.log(a);};

    var i = 0;
    var ret = {};
    var e = questions[0];
    var v = match(ops, e);

    output(getOutput(e, v));
    input(getInput);

    function getOutput(e, v) {
        var o = f.isFunction(v.output)? v.output(e): '';

        return e.q + o;
    }

    function getInput(t) {
        t = t.trim();
        var r = v.exec(t, e);

        if(f.isDefined(r)) {
            ret[e.id] = r;
            i++;

            if(i >= questions.length) {
                // XXX: separate this somehow
                process.stdin.removeListener('data', getInput);
                process.stdin.pause();

                finish(ret);
            }
            else {
                e = questions[i];
                v = match(ops, e);
                output(getOutput(e, v));
            }
        }
    }
}
900911
@Nonnull
    private static File writeDataToTempFileOrDie(@Nonnull final OutputStreamCallback callback,
                                                 @Nonnull final File targetFile,
                                                 @Nonnull final Logger log) throws IOException {
        Preconditions.checkNotNull(callback, "callback argument is required!");
        Preconditions.checkNotNull(log, "log argument is required!");
        Preconditions.checkNotNull(targetFile, "targetFile argument is required!");

        FileOutputStream fileOut = null;
        FileChannel fileChannel = null;
        try {
            final String targetFinalName = targetFile.getName();
            final File targetDirectory = targetFile.getParentFile();

            // open temporary file
            final File tmpFile = File.createTempFile(targetFinalName, ".tmp", targetDirectory);

            fileOut = new FileOutputStream(tmpFile);
            fileChannel = fileOut.getChannel();

            // make sure to use an output stream that flows THROUGH the FileChannel, so that FileChannel.force(true)
            // can do what it's supposed to

            // write the data AND flush it
            callback.writeAndFlushData(Channels.newOutputStream(fileChannel));

            return tmpFile;
        } finally {
            try {
                // fsync to disk (both data AND length)
                if (fileChannel != null) {
                    fileChannel.force(true);
                }
            } finally {
                // close the open file (if during an EXC,
                if (fileOut != null) {
                    fileOut.close();
                }
            }
        }
    }
503634
public static function ask($text, $callback = null, $text_color = null, $bg_color = null)
    {
        if (null === $callback) {
            $callback = function() {
                return true;
            };
        }

        do {
            self::write($text, $text_color, $bg_color);
        } while (!$callback($answer = self::read()));

        return $answer;
    }
53457
function callbackOnce(err, arg) {
            var cb = callback;
            callback = null;
            if (cb) { cb(err, arg); }
        }
82015
function(callback) {

				// if there’s anything to optimize…
				if (outputFiles.length > 0) {

					// get absolute paths to the stuff we’re optimizing
					var outputFilesResolved = outputFiles.map(function(dir) {
						return path.resolve(__dirname, '../' + dir);
					});

					// optimize as many times as the user wants
					async.timesSeries(options.optimize.output.imageOptim, function(i, next) {

						// let the user know that we’re optimizing inputs
						grunt.log.writeln('Optimizing outputs with ImageOptim (pass ' + (i + 1) + ' of ' + options.optimize.output.imageOptim + ')…');

						// do the optimizations (with promises)
						optimizeImageOptim(outputFilesResolved, binPath.imageOptim).then(function() {
							next();
						});

					}, callback);

				} else {
					callback(null);
				}

			}
124897
function(p, callback) {

		var _this = this;
		var error = _this.error;

		// This has to go through a POST request
		if (!_this.isEmpty(p.data) && !('FileList' in window) && _this.hasBinary(p.data)) {

			// Disable XHR and JSONP
			p.xhr = false;
			p.jsonp = false;
		}

		// Check if the browser and service support CORS
		var cors = this.request_cors(function() {
			// If it does then run this...
			return ((p.xhr === undefined) || (p.xhr && (typeof (p.xhr) !== 'function' || p.xhr(p, p.query))));
		});

		if (cors) {

			formatUrl(p, function(url) {

				var x = _this.xhr(p.method, url, p.headers, p.data, callback);
				x.onprogress = p.onprogress || null;

				// Windows Phone does not support xhr.upload, see #74
				// Feature detect
				if (x.upload && p.onuploadprogress) {
					x.upload.onprogress = p.onuploadprogress;
				}

			});

			return;
		}

		// Clone the query object
		// Each request modifies the query object and needs to be tared after each one.
		var _query = p.query;

		p.query = _this.clone(p.query);

		// Assign a new callbackID
		p.callbackID = _this.globalEvent();

		// JSONP
		if (p.jsonp !== false) {

			// Clone the query object
			p.query.callback = p.callbackID;

			// If the JSONP is a function then run it
			if (typeof (p.jsonp) === 'function') {
				p.jsonp(p, p.query);
			}

			// Lets use JSONP if the method is 'get'
			if (p.method === 'get') {

				formatUrl(p, function(url) {
					_this.jsonp(url, callback, p.callbackID, p.timeout);
				});

				return;
			}
			else {
				// It's not compatible reset query
				p.query = _query;
			}

		}

		// Otherwise we're on to the old school, iframe hacks and JSONP
		if (p.form !== false) {

			// Add some additional query parameters to the URL
			// We're pretty stuffed if the endpoint doesn't like these
			p.query.redirect_uri = p.redirect_uri;
			p.query.state = JSON.stringify({callback:p.callbackID});

			var opts;

			if (typeof (p.form) === 'function') {

				// Format the request
				opts = p.form(p, p.query);
			}

			if (p.method === 'post' && opts !== false) {

				formatUrl(p, function(url) {
					_this.post(url, p.data, opts, callback, p.callbackID, p.timeout);
				});

				return;
			}
		}

		// None of the methods were successful throw an error
		callback(error('invalid_request', 'There was no mechanism for handling this request'));

		return;

		// Format URL
		// Constructs the request URL, optionally wraps the URL through a call to a proxy server
		// Returns the formatted URL
		function formatUrl(p, callback) {

			// Are we signing the request?
			var sign;

			// OAuth1
			// Remove the token from the query before signing
			if (p.authResponse && p.authResponse.oauth && parseInt(p.authResponse.oauth.version, 10) === 1) {

				// OAUTH SIGNING PROXY
				sign = p.query.access_token;

				// Remove the access_token
				delete p.query.access_token;

				// Enfore use of Proxy
				p.proxy = true;
			}

			// POST body to querystring
			if (p.data && (p.method === 'get' || p.method === 'delete')) {
				// Attach the p.data to the querystring.
				_this.extend(p.query, p.data);
				p.data = null;
			}

			// Construct the path
			var path = _this.qs(p.url, p.query);

			// Proxy the request through a server
			// Used for signing OAuth1
			// And circumventing services without Access-Control Headers
			if (p.proxy) {
				// Use the proxy as a path
				path = _this.qs(p.oauth_proxy, {
					path: path,
					access_token: sign || '',

					// This will prompt the request to be signed as though it is OAuth1
					then: p.proxy_response_type || (p.method.toLowerCase() === 'get' ? 'redirect' : 'proxy'),
					method: p.method.toLowerCase(),
					suppress_response_codes: true
				});
			}

			callback(path);
		}
	}
209840
function(callback) {
            if (resumeEnabled) {
                qq.each(localStorage, function(key, item) {
                    if (key.indexOf(qq.format("qq{}resume", namespace)) === 0) {
                        var uploadData = JSON.parse(item);
                        callback(key, uploadData);
                    }
                });
            }
        }
503361
function execute(command, callback){
  exec(command, function(error, stdout, stderr){ callback(error, stdout); });
}
902230
function(callback) {
      fs.exists(options.source, function(exists) {
        if(!exists) { callback(new Error('Source file do not exists!')); }
        else { callback(null, true); }
      });
    }
921716
function (callback) {
            callback = backpack.ensure(callback, this);

            if (!this.paused) { return callback && callback(new Error('run: not paused')); }

            // set flag that it is no longer paused and fire the stored callback for the command when it was paused
            this.paused = false;
            setTimeout(function () {
                this.__resume();
                delete this.__resume;
                this.triggers.resume(null, this.state.cursor.current());
            }.bind(this), 0);

            callback && callback();
        }
47550
function processFile(rootPath, log) {
  return (file, callback) => {
    const filePath = path.join(rootPath, file.path);
    const writeMode = isStream(file.data) ? WriteMode.STREAM : WriteMode.UTF8;
    write(filePath, file.data, writeMode, (error) => {
      if (log === true && !error) {
        console.log(`Successfully wrote file '${file.path}'`);
      }

      async.nextTick(callback, error, file);
    });
  };
}
377676
function (fp, cb) {
    if (typeof fp === 'function') {
      cb = fp;
      fp = null;
    }

    if (typeof cb !== 'function') {
      throw new Error('async `write` was called without a callback function.');
    }

    var dest = fp || this.dest.path;
    var src = this.src.path;
    var str = this.content;
    var opts = this.options || {};
    if (typeof opts.force !== 'boolean') {
      opts.force = true;
    }

    lazy.detect(this, opts, function () {
      if (str) {
        lazy.write(dest, str, cb);
      } else {
        lazy.copy(src, dest, cb);
      }
    });

    this.emit('write', dest);
    return this;
  }
982223
function (args, callback) {
        if (ternserver) {
          ternserver.request({
              query: {
                type: "documentation",  //$NON-NLS-1$
                file: args.meta.location,
                end: args.params.offset,
                docFormat: args.params.docFormat
              },
              files: args.files
            },
            function (error, doc) {
              if (error) {
                callback({request: 'documentation', error: error.message, message: Messages['failedToComputeDoc']}); //$NON-NLS-1$
              } else if (doc && doc.doc) {
                callback({request: 'documentation', doc: doc}); //$NON-NLS-1$
              } else {
                callback({request: 'documentation', doc: null}); //$NON-NLS-1$
              }
            });
        } else {
          callback({request: 'documentation', message: Messages['failedToComputeDocNoServer']}); //$NON-NLS-1$
        }
      }