src/Console/CommandTrait.php
protected function parseFile($name, Closure $callback)
    {
        $url = $this->files[$name]['url'];
        $basename = basename($url);
        $storagePath = config('geonames.storagePath');
        // Final file path
        $path = $storagePath . '/' . $this->files[$name]['filename'] . '.txt';

        // Check if file exists (should be since we just downloaded them)
        $downloadedFilePath = $storagePath . '/' . $basename;
        if (!file_exists($downloadedFilePath)) {
            throw new RuntimeException('File does not exist: ' . $downloadedFilePath);
        }
        // If it is a zip file we must unzip it
        if (substr($basename, -4) === '.zip') {
            $this->unZip($name);
        }

        $steps = $this->getLineCount($path);

        /* @var $output OutputStyle */
        $output = $this->getOutput();
        $bar = $output->createProgressBar($steps);
        $bar->setFormat('<info>Seeding File:</info> ' . basename($path) . ' %current%/%max% %bar% %percent%% <info>Remaining Time:</info> %remaining%');

        $steps = 0;
        $fh = fopen($path, 'r');
        if (!$fh) {
            throw new RuntimeException("Can not open file: $path");
        }
        while (!feof($fh)) {
            $line = fgets($fh);
            // ignore empty lines and comments
            if (!$line or $line === '' or strpos($line, '#') === 0) continue;
            // Geonames format is tab seperated
            $line = explode("\t", $line);
            // Insert using closure
            $callback($line);
            $steps++;
            if (isset($bar) && $steps % ($this->bufferSize * 10) === 0)
                $bar->advance($this->bufferSize * 10);
        }
        fclose($fh);
        if (isset($bar)) {
            $bar->finish();
            $output->newLine();
        }
        // If we wont keep txt version delete file
        if (substr($basename, -4) === '.zip' && !config('geonames.keepTxt')) {
            $this->line('<info>Removing File:</info> ' . basename($path));
            unlink($path);
        }
    }
protected function parseFile($name, Closure $callback)
    {
        $url = $this->files[$name]['url'];
        $basename = basename($url);
        $storagePath = config('geonames.storagePath');
        // Final file path
        $path = $storagePath . '/' . $this->files[$name]['filename'] . '.txt';

        // Check if file exists (should be since we just downloaded them)
        $downloadedFilePath = $storagePath . '/' . $basename;
        if (!file_exists($downloadedFilePath)) {
            throw new RuntimeException('File does not exist: ' . $downloadedFilePath);
        }
        // If it is a zip file we must unzip it
        if (substr($basename, -4) === '.zip') {
            $this->unZip($name);
        }

        $steps = $this->getLineCount($path);

        /* @var $output OutputStyle */
        $output = $this->getOutput();
        $bar = $output->createProgressBar($steps);
        $bar->setFormat('<info>Seeding File:</info> ' . basename($path) . ' %current%/%max% %bar% %percent%% <info>Remaining Time:</info> %remaining%');

        $steps = 0;
        $fh = fopen($path, 'r');
        if (!$fh) {
            throw new RuntimeException("Can not open file: $path");
        }
        while (!feof($fh)) {
            $line = fgets($fh);
            // ignore empty lines and comments
            if (!$line or $line === '' or strpos($line, '#') === 0) continue;
            // Geonames format is tab seperated
            $line = explode("\t", $line);
            // Insert using closure
            $callback($line);
            $steps++;
            if (isset($bar) && $steps % ($this->bufferSize * 10) === 0)
                $bar->advance($this->bufferSize * 10);
        }
        fclose($fh);
        if (isset($bar)) {
            $bar->finish();
            $output->newLine();
        }
        // If we wont keep txt version delete file
        if (substr($basename, -4) === '.zip' && !config('geonames.keepTxt')) {
            $this->line('<info>Removing File:</info> ' . basename($path));
            unlink($path);
        }
    }
Parse a given file and insert into databaase using closure.

@param  string $name
@param  Closure $callback
@return void