Skip to content

Write to files

use Innmind\IO\IO;
use Innmind\Url\Path;
use Innmind\Immutable\{
    Sequence,
    Str,
};

$successful = IO::fromAmbientAuthority()
    ->files()
    ->write(Path::of('/path/to/file.ext'))
    ->sink(Sequence::of(
        Str::of('chunk 1'),
        Str::of("new line \n"),
        Str::of('chunk 2'),
        Str::of('etc...'),
    ));

$successful is an instance of Attempt<SideEffect>.

Since the data to write is expressed with a Sequence, you can use a lazy one to create files that may not fit in memory.