Truncate

To truncate the stream to a specific size, use truncate().

$stream = FileStream::open('persons.txt', 'r')
    ->truncate(0);

echo $stream->getSize(); // 0
$stream = FileStream::open('persons.txt', 'r')
    ->truncate(25);

echo $stream->getSize(); // 25

Behind the scene, PHP's ftruncate()open in new window is used to truncate stream.