skt-t1-byungi/into-one

将文件合并成一个

1.0.2 2016-11-21 14:47 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:58:07 UTC


README

将文件合并成一个

Latest Stable Version Total Downloads License

描述

用于合并多个文件以便于管理的工具。

用法

namespace SktT1Byungi\IntoOne;

$path = "test.bin";

var_dump(is_file($path)); //false;

IntoOne::concat($path, function ($add) {
    $add->data('key1', 'abcd');
    $add->path('key2', 'files/test.txt');
    $add->resource('key3', fopen('php://stdin', 'r'));
});

var_dump(is_file($path)); //true;

$data = IntoOne::read($path, 'key1'); // $data == 'abcd'

//for large file
$content = '';
IntoOne::readChunks($path, "key2", function ($chunk) use ($content) {
    $content .= $chunk;
});

//$content == file_get_contents("files/test.txt")

无门面(facade)

namespace SktT1Byungi\IntoOne;

$path = "test.bin";

$resource = Resource::fopen($path, 'w');
$concat = new Concat($resource);
$add = new Add($concat);

$add->data('key1', 'abcd');
$add->path('key2', 'files/test.txt');
$add->resource('key3', fopen('php://stdin', 'r'));

$concat->finish();

许可协议

MIT