public static function exportBytes($str, $all = false)
    {
        return preg_replace_callback(
            '~' . ($all ? '.' : '[^A-Za-z\d\.\{\}$<>:;\-_/\\\\=+]') . '~s',
            function ($m) use ($all) {
                if (!$all) {
                    if ($m[0] === "\r") {
                        return "\n" . '\r';
                    }

                    if ($m[0] === "\n") {
                        return '\n';
                    }
                }

                return sprintf('\x%02x', ord($m[0]));
            },
            $str
        );
    }