Delete response body content

Is there a way to delete the entire response body content, after it has been written to it?
Like this.

Stream.php

public function truncate() {
    ftruncate($this->stream, 0);
}

probably by replacing with an empty PSR-7 valid object. Check out this from the docs:

You can also replace the PSR 7 Response object’s body with an entirely new StreamInterface instance.

An example:

$newStream = new \GuzzleHttp\Psr7\LazyOpenStream('/path/to/file', 'r');
$newResponse = $oldResponse->withBody($newStream);

Source

Look promising.
But in case I would prefer to create an empty file stream from memory and an build in solution would be nice, too?

Anyway my slim skeleton implementation does not seem to come with Guzzle, do I have to download it from github separately?

Easy way in Slim Framework 3. This works fine for me.

public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $args = null)
{
    // Get response set by middleware.
    $mw_response = $response->getBody()->__toString();

    // Now reset the response.
    $response = new \Slim\Http\Response();

    .....
}