Temporary¶
use Innmind\IO\IO;
use Innmind\Immutable\{
Sequence,
Str,
};
$temporary = IO::fromAmbientAuthority()
->files()
->temporary(Sequence::of(
Str::of('chunk 1'),
Str::of("new line \n"),
Str::of('chunk 2'),
Str::of('etc...'),
))
->unwrap();
This creates a temporary file without having to think about where to store it.
You can then use it in 2 ways:
Once you're down working with the file you can close it like this:
Incremental file creation¶
When bridging this library with a more imperative API, using the Sequence
to declare the chunks of the temporary file may not be possible.
Info
This is the case with the curl
extension for example.
In this case you need to use the push strategy: