2017 © Pedro Peláez
 

library file

File utility library for hacklang

image

minimalist/file

File utility library for hacklang

  • Wednesday, March 25, 2015
  • by holyshared
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • Hack
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

file

Latest Stable Version Build Status Dependency Status License, (*1)

This package is a library for performing a simple to file operations hacklang.
Will provide a lightweight and simple api to the user., (*2)

Basic usage

Read processing of files can be realized by a simple code as follows., (*3)

Reading one line at a time.

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
};

Read the CSV file

use HHPack\File\FileLineStream;
use HHPack\File\SeparatedRecordStream;
use HHPack\File\ColumnSpecification;

$spec = new ColumnSpecification(',', '"');
$spec->addColumn(0, 'name');
$spec->addColumn(1, 'description');

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

foreach ($csvStream as $record) {
    echo $record->get('name'), "\n";
    echo $record->get('description'), "\n";
}

Customizing the reading of the record

Will create a parser that implements the ParseSpecification.
Then use the ParsedFileReader, and then apply the parser., (*4)

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";
}

Run the test

You can run the test with the following command., (*5)

composer install
composer test

The Versions

25/03 2015

dev-master

9999999-dev

File utility library for hacklang

  Sources   Download

The Requires

  • hhvm ~3.5

 

The Development Requires

by Noritaka Horio

file utility easy simple hacklang