A small wrapper for some php file streaming functions with support for inserting data into streams without overwriting. (Also: chainable.)
Add to composer:
require: {
"prewk/file-chainer": "dev-master"
}
And run composer install
.
Two new file stream methods:
finsert
inserts a string at the current file stream positionfinsertcsv
inserts a csv (like fputcsv) line at the current file stream position
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
$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