PHP code example of hhpack / file

1. Go to this page and download the library: Download hhpack/file library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hhpack / file example snippets

hack
use HHPack\File\FileLineStream;

$lineStream = FileLineStream::fromString('/path/to/text.log');

foreach ($lineStream as $line) {
	echo $line->length(), "\n"; //output length
	echo $line->value(), "\n"; //output content
};
hack
use HHPack\File\FileLineStream;
use HHPack\File\ParsedChunkStream;
use HHPack\File\ParseSpecification;

final class CustomRecordSpecification implements ParseSpecification<array<string>>
{
    public function parse(Chunk $line) : array<string>
    {
        return $line->split(',');
    }
}

$spec = new CustomRecordSpecification();
$lineStream = FileLineStream::fromString(__DIR__ . '/example.csv');
$csvStream = new ParsedChunkStream($lineStream, $spec);

foreach ($csvStream as $values) {
    echo $values[0], "\n";
    echo $values[1], "\n";
}