Skip to content
Chainable file stream writer with insert support
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
README.md
composer.json
composer.lock
phpunit.xml

README.md

file-chainer Build Status

What is it?

A small wrapper for some php file streaming functions with support for inserting data into streams without overwriting. (Also: chainable.)

Installation

Add to composer:

require: {
    "prewk/file-chainer": "dev-master"
}

And run composer install.

Usage

Two new file stream methods:

  • finsert inserts a string at the current file stream position
  • finsertcsv inserts a csv (like fputcsv) line at the current file stream position

Inserting & chaining

Prewk\FileChainer::make()
    ->fopen("/foo/bar.txt", "w+")
    ->fwrite("foo")
    ->rewind()
    ->finsert("bar")
    ->fclose();

echo file_get_contents("/foo/bar.txt");
// Output: barfoo
// The handle's file pointer = 3

Inserting with static method

$handle = fopen("/foo/bar.txt", "w+");
fwrite($handle, "foo");
rewind($handle);

// Statically, using the default "temporary file stream" method
Prewk\FileChainer\Inserters\File::finsert($handle, "bar");

fclose($handle);

echo file_get_contents("/foo/bar.txt");
// Output: barfoo
// The handle's file pointer = 3
You can’t perform that action at this time.