public static function copy($stream, $close = true)
    {
        $cloned = fopen('php://temp', 'w+b');
        $pos = ftell($stream);

        static::tryRewind($stream);
        stream_copy_to_stream($stream, $cloned);

        if ($close) {
            fclose($stream);
        } else {
            static::trySeek($stream, $pos);
        }

        fseek($cloned, $pos);

        return $cloned;
    }