{"action":"created","comment":{"url":"https://api.github.com/repos/samdark/sitemap/pulls/comments/165374838","pull_request_review_id":93288914,"id":165374838,"diff_hunk":"@@ -173,66 +204,30 @@ public function write()\n \n     /**\n      * Flushes buffer into file\n-     * @param bool $finishFile Pass true to close the file to write to, used only when useGzip is true\n+     *\n+     * @param int $footSize Size of the remaining closing tags\n+     * @throws \\OverflowException\n      */\n-    private function flush($finishFile = false)\n+    private function flush($footSize = 10)\n     {\n-        if ($this->useGzip) {\n-            $this->flushGzip($finishFile);\n-            return;\n-        }\n-        file_put_contents($this->getCurrentFilePath(), $this->writer->flush(true), FILE_APPEND);\n-    }\n-\n-    /**\n-     * Decides how to flush buffer into compressed file\n-     * @param bool $finishFile Pass true to close the file to write to\n-     */\n-    private function flushGzip($finishFile = false) {\n-        if (function_exists('deflate_init') && function_exists('deflate_add')) {\n-            $this->flushWithIncrementalDeflate($finishFile);\n-            return;\n-        }\n-        $this->flushWithTempFileFallback($finishFile);\n-    }\n-\n-    /**\n-     * Flushes buffer into file with incremental deflating data, available in php 7.0+\n-     * @param bool $finishFile Pass true to write last chunk with closing headers\n-     */\n-    private function flushWithIncrementalDeflate($finishFile = false) {\n-        $flushMode = $finishFile ? ZLIB_FINISH : ZLIB_NO_FLUSH;\n-\n-        if (empty($this->deflateContext)) {\n-            $this->deflateContext = deflate_init(ZLIB_ENCODING_GZIP);\n-        }\n-        \n-        $compressedChunk = deflate_add($this->deflateContext, $this->writer->flush(true), $flushMode);\n-        file_put_contents($this->getCurrentFilePath(), $compressedChunk, FILE_APPEND);\n-\n-        if ($finishFile) {\n-            $this->deflateContext = null;\n-        }\n-    }\n-\n-    /**\n-     * Flushes buffer into temporary stream and compresses stream into a file on finish\n-     * @param bool $finishFile Pass true to compress temporary stream into desired file\n-     */\n-    private function flushWithTempFileFallback($finishFile = false) {\n-        if (empty($this->tempFile) || !is_resource($this->tempFile)) {\n-            $this->tempFile = fopen('php://temp/', 'w');\n+        $data = $this->writer->flush(true);\n+\n+        /**\n+         * Limit the file size of each single site map\n+         *\n+         * We use a heuristic of 10 Bytes for the remainder of the file,\n+         * i.e. </urlset> plus a new line.\n+         */\n+        if ($this->byteCount + strlen($data) + $footSize > $this->maxBytes) {\n+            if ($this->urlsCount <= 1) {\n+                throw new \\OverflowException('The buffer size is too big for the defined file size limit');\n+            }\n+            $this->finishFile();\n+            $this->createNewFile();\n         }\n \n-        fwrite($this->tempFile, $this->writer->flush(true));\n-\n-        if ($finishFile) {\n-            $file = fopen('compress.zlib://' . $this->getCurrentFilePath(), 'w');\n-            rewind($this->tempFile);\n-            stream_copy_to_stream($this->tempFile, $file);\n-            fclose($file);\n-            fclose($this->tempFile);\n-        }\n+        $this->writerBackend->append($data);\n+        $this->byteCount += strlen($data);","path":"Sitemap.php","position":182,"original_position":182,"commit_id":"2733b134ae048f5dde0a273c1c2b2c6dce515b4e","original_commit_id":"2733b134ae048f5dde0a273c1c2b2c6dce515b4e","user":{"login":"samdark","id":47294,"avatar_url":"https://avatars2.githubusercontent.com/u/47294?v=4","gravatar_id":"","url":"https://api.github.com/users/samdark","html_url":"https://github.com/samdark","followers_url":"https://api.github.com/users/samdark/followers","following_url":"https://api.github.com/users/samdark/following{/other_user}","gists_url":"https://api.github.com/users/samdark/gists{/gist_id}","starred_url":"https://api.github.com/users/samdark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samdark/subscriptions","organizations_url":"https://api.github.com/users/samdark/orgs","repos_url":"https://api.github.com/users/samdark/repos","events_url":"https://api.github.com/users/samdark/events{/privacy}","received_events_url":"https://api.github.com/users/samdark/received_events","type":"User","site_admin":false},"body":"`mb_strlen($data, '8bit');` should be used in order not to break when mb_ overload is active in php.ini.","created_at":"2018-02-01T14:41:01Z","updated_at":"2018-02-01T14:46:13Z","html_url":"https://github.com/samdark/sitemap/pull/55#discussion_r165374838","pull_request_url":"https://api.github.com/repos/samdark/sitemap/pulls/55","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/samdark/sitemap/pulls/comments/165374838"},"html":{"href":"https://github.com/samdark/sitemap/pull/55#discussion_r165374838"},"pull_request":{"href":"https://api.github.com/repos/samdark/sitemap/pulls/55"}}},"pull_request":{"url":"https://api.github.com/repos/samdark/sitemap/pulls/55","id":166422413,"html_url":"https://github.com/samdark/sitemap/pull/55","diff_url":"https://github.com/samdark/sitemap/pull/55.diff","patch_url":"https://github.com/samdark/sitemap/pull/55.patch","issue_url":"https://api.github.com/repos/samdark/sitemap/issues/55","number":55,"state":"open","locked":false,"title":"Fixes issue #17. Allow to set a file size limit","user":{"login":"bodograumann","id":1223583,"avatar_url":"https://avatars1.githubusercontent.com/u/1223583?v=4","gravatar_id":"","url":"https://api.github.com/users/bodograumann","html_url":"https://github.com/bodograumann","followers_url":"https://api.github.com/users/bodograumann/followers","following_url":"https://api.github.com/users/bodograumann/following{/other_user}","gists_url":"https://api.github.com/users/bodograumann/gists{/gist_id}","starred_url":"https://api.github.com/users/bodograumann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bodograumann/subscriptions","organizations_url":"https://api.github.com/users/bodograumann/orgs","repos_url":"https://api.github.com/users/bodograumann/repos","events_url":"https://api.github.com/users/bodograumann/events{/privacy}","received_events_url":"https://api.github.com/users/bodograumann/received_events","type":"User","site_admin":false},"body":"This adds a default file size limit of 10 MiB for all site map files.\r\nUse `Sitemap::setMaxBytes` to set a custom value.\r\n\r\nThere were some changes necessary to make this feasible.\r\nIn particular I reduced the default buffer size to 10 and refactored the\r\nfile writing back ends into separate classes.\r\nI also added some tests.\r\n\r\nUpdate:\r\nThere was some weird 403 HTTP-Error in travis when accessing \r\nhttps://www.w3.org/2001/xml.xsd. I hope this goes away by itself.\r\n\r\nApart from that I have replaced the array short forms in the last commit\r\nand slightly reduced the performance requirements in the timing test\r\nfrom +10% to +20%. (Actual numbers in two tests where +11% and +14%,\r\nall other where below +10%)","created_at":"2018-02-01T01:35:46Z","updated_at":"2018-02-01T14:46:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"16208674e54eeb553c926255a04b27f8d11f7907","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/samdark/sitemap/pulls/55/commits","review_comments_url":"https://api.github.com/repos/samdark/sitemap/pulls/55/comments","review_comment_url":"https://api.github.com/repos/samdark/sitemap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/samdark/sitemap/issues/55/comments","statuses_url":"https://api.github.com/repos/samdark/sitemap/statuses/2733b134ae048f5dde0a273c1c2b2c6dce515b4e","head":{"label":"bodograumann:sizelimit","ref":"sizelimit","sha":"2733b134ae048f5dde0a273c1c2b2c6dce515b4e","user":{"login":"bodograumann","id":1223583,"avatar_url":"https://avatars1.githubusercontent.com/u/1223583?v=4","gravatar_id":"","url":"https://api.github.com/users/bodograumann","html_url":"https://github.com/bodograumann","followers_url":"https://api.github.com/users/bodograumann/followers","following_url":"https://api.github.com/users/bodograumann/following{/other_user}","gists_url":"https://api.github.com/users/bodograumann/gists{/gist_id}","starred_url":"https://api.github.com/users/bodograumann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bodograumann/subscriptions","organizations_url":"https://api.github.com/users/bodograumann/orgs","repos_url":"https://api.github.com/users/bodograumann/repos","events_url":"https://api.github.com/users/bodograumann/events{/privacy}","received_events_url":"https://api.github.com/users/bodograumann/received_events","type":"User","site_admin":false},"repo":{"id":119725027,"name":"sitemap","full_name":"bodograumann/sitemap","owner":{"login":"bodograumann","id":1223583,"avatar_url":"https://avatars1.githubusercontent.com/u/1223583?v=4","gravatar_id":"","url":"https://api.github.com/users/bodograumann","html_url":"https://github.com/bodograumann","followers_url":"https://api.github.com/users/bodograumann/followers","following_url":"https://api.github.com/users/bodograumann/following{/other_user}","gists_url":"https://api.github.com/users/bodograumann/gists{/gist_id}","starred_url":"https://api.github.com/users/bodograumann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bodograumann/subscriptions","organizations_url":"https://api.github.com/users/bodograumann/orgs","repos_url":"https://api.github.com/users/bodograumann/repos","events_url":"https://api.github.com/users/bodograumann/events{/privacy}","received_events_url":"https://api.github.com/users/bodograumann/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bodograumann/sitemap","description":"Sitemap and sitemap index builder","fork":true,"url":"https://api.github.com/repos/bodograumann/sitemap","forks_url":"https://api.github.com/repos/bodograumann/sitemap/forks","keys_url":"https://api.github.com/repos/bodograumann/sitemap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bodograumann/sitemap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bodograumann/sitemap/teams","hooks_url":"https://api.github.com/repos/bodograumann/sitemap/hooks","issue_events_url":"https://api.github.com/repos/bodograumann/sitemap/issues/events{/number}","events_url":"https://api.github.com/repos/bodograumann/sitemap/events","assignees_url":"https://api.github.com/repos/bodograumann/sitemap/assignees{/user}","branches_url":"https://api.github.com/repos/bodograumann/sitemap/branches{/branch}","tags_url":"https://api.github.com/repos/bodograumann/sitemap/tags","blobs_url":"https://api.github.com/repos/bodograumann/sitemap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bodograumann/sitemap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bodograumann/sitemap/git/refs{/sha}","trees_url":"https://api.github.com/repos/bodograumann/sitemap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bodograumann/sitemap/statuses/{sha}","languages_url":"https://api.github.com/repos/bodograumann/sitemap/languages","stargazers_url":"https://api.github.com/repos/bodograumann/sitemap/stargazers","contributors_url":"https://api.github.com/repos/bodograumann/sitemap/contributors","subscribers_url":"https://api.github.com/repos/bodograumann/sitemap/subscribers","subscription_url":"https://api.github.com/repos/bodograumann/sitemap/subscription","commits_url":"https://api.github.com/repos/bodograumann/sitemap/commits{/sha}","git_commits_url":"https://api.github.com/repos/bodograumann/sitemap/git/commits{/sha}","comments_url":"https://api.github.com/repos/bodograumann/sitemap/comments{/number}","issue_comment_url":"https://api.github.com/repos/bodograumann/sitemap/issues/comments{/number}","contents_url":"https://api.github.com/repos/bodograumann/sitemap/contents/{+path}","compare_url":"https://api.github.com/repos/bodograumann/sitemap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bodograumann/sitemap/merges","archive_url":"https://api.github.com/repos/bodograumann/sitemap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bodograumann/sitemap/downloads","issues_url":"https://api.github.com/repos/bodograumann/sitemap/issues{/number}","pulls_url":"https://api.github.com/repos/bodograumann/sitemap/pulls{/number}","milestones_url":"https://api.github.com/repos/bodograumann/sitemap/milestones{/number}","notifications_url":"https://api.github.com/repos/bodograumann/sitemap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bodograumann/sitemap/labels{/name}","releases_url":"https://api.github.com/repos/bodograumann/sitemap/releases{/id}","deployments_url":"https://api.github.com/repos/bodograumann/sitemap/deployments","created_at":"2018-01-31T18:17:25Z","updated_at":"2018-01-31T18:17:27Z","pushed_at":"2018-02-01T09:20:37Z","git_url":"git://github.com/bodograumann/sitemap.git","ssh_url":"git@github.com:bodograumann/sitemap.git","clone_url":"https://github.com/bodograumann/sitemap.git","svn_url":"https://github.com/bodograumann/sitemap","homepage":"","size":86,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"samdark:master","ref":"master","sha":"7b1df0d84075f9d1c6968641c176151278c614a5","user":{"login":"samdark","id":47294,"avatar_url":"https://avatars2.githubusercontent.com/u/47294?v=4","gravatar_id":"","url":"https://api.github.com/users/samdark","html_url":"https://github.com/samdark","followers_url":"https://api.github.com/users/samdark/followers","following_url":"https://api.github.com/users/samdark/following{/other_user}","gists_url":"https://api.github.com/users/samdark/gists{/gist_id}","starred_url":"https://api.github.com/users/samdark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samdark/subscriptions","organizations_url":"https://api.github.com/users/samdark/orgs","repos_url":"https://api.github.com/users/samdark/repos","events_url":"https://api.github.com/users/samdark/events{/privacy}","received_events_url":"https://api.github.com/users/samdark/received_events","type":"User","site_admin":false},"repo":{"id":38269371,"name":"sitemap","full_name":"samdark/sitemap","owner":{"login":"samdark","id":47294,"avatar_url":"https://avatars2.githubusercontent.com/u/47294?v=4","gravatar_id":"","url":"https://api.github.com/users/samdark","html_url":"https://github.com/samdark","followers_url":"https://api.github.com/users/samdark/followers","following_url":"https://api.github.com/users/samdark/following{/other_user}","gists_url":"https://api.github.com/users/samdark/gists{/gist_id}","starred_url":"https://api.github.com/users/samdark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samdark/subscriptions","organizations_url":"https://api.github.com/users/samdark/orgs","repos_url":"https://api.github.com/users/samdark/repos","events_url":"https://api.github.com/users/samdark/events{/privacy}","received_events_url":"https://api.github.com/users/samdark/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/samdark/sitemap","description":"Sitemap and sitemap index builder","fork":false,"url":"https://api.github.com/repos/samdark/sitemap","forks_url":"https://api.github.com/repos/samdark/sitemap/forks","keys_url":"https://api.github.com/repos/samdark/sitemap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samdark/sitemap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samdark/sitemap/teams","hooks_url":"https://api.github.com/repos/samdark/sitemap/hooks","issue_events_url":"https://api.github.com/repos/samdark/sitemap/issues/events{/number}","events_url":"https://api.github.com/repos/samdark/sitemap/events","assignees_url":"https://api.github.com/repos/samdark/sitemap/assignees{/user}","branches_url":"https://api.github.com/repos/samdark/sitemap/branches{/branch}","tags_url":"https://api.github.com/repos/samdark/sitemap/tags","blobs_url":"https://api.github.com/repos/samdark/sitemap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samdark/sitemap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samdark/sitemap/git/refs{/sha}","trees_url":"https://api.github.com/repos/samdark/sitemap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samdark/sitemap/statuses/{sha}","languages_url":"https://api.github.com/repos/samdark/sitemap/languages","stargazers_url":"https://api.github.com/repos/samdark/sitemap/stargazers","contributors_url":"https://api.github.com/repos/samdark/sitemap/contributors","subscribers_url":"https://api.github.com/repos/samdark/sitemap/subscribers","subscription_url":"https://api.github.com/repos/samdark/sitemap/subscription","commits_url":"https://api.github.com/repos/samdark/sitemap/commits{/sha}","git_commits_url":"https://api.github.com/repos/samdark/sitemap/git/commits{/sha}","comments_url":"https://api.github.com/repos/samdark/sitemap/comments{/number}","issue_comment_url":"https://api.github.com/repos/samdark/sitemap/issues/comments{/number}","contents_url":"https://api.github.com/repos/samdark/sitemap/contents/{+path}","compare_url":"https://api.github.com/repos/samdark/sitemap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samdark/sitemap/merges","archive_url":"https://api.github.com/repos/samdark/sitemap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samdark/sitemap/downloads","issues_url":"https://api.github.com/repos/samdark/sitemap/issues{/number}","pulls_url":"https://api.github.com/repos/samdark/sitemap/pulls{/number}","milestones_url":"https://api.github.com/repos/samdark/sitemap/milestones{/number}","notifications_url":"https://api.github.com/repos/samdark/sitemap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samdark/sitemap/labels{/name}","releases_url":"https://api.github.com/repos/samdark/sitemap/releases{/id}","deployments_url":"https://api.github.com/repos/samdark/sitemap/deployments","created_at":"2015-06-29T20:23:31Z","updated_at":"2018-02-01T13:51:26Z","pushed_at":"2018-02-01T09:20:38Z","git_url":"git://github.com/samdark/sitemap.git","ssh_url":"git@github.com:samdark/sitemap.git","clone_url":"https://github.com/samdark/sitemap.git","svn_url":"https://github.com/samdark/sitemap","homepage":"","size":69,"stargazers_count":299,"watchers_count":299,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":52,"mirror_url":null,"archived":false,"open_issues_count":10,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":52,"open_issues":10,"watchers":299,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/samdark/sitemap/pulls/55"},"html":{"href":"https://github.com/samdark/sitemap/pull/55"},"issue":{"href":"https://api.github.com/repos/samdark/sitemap/issues/55"},"comments":{"href":"https://api.github.com/repos/samdark/sitemap/issues/55/comments"},"review_comments":{"href":"https://api.github.com/repos/samdark/sitemap/pulls/55/comments"},"review_comment":{"href":"https://api.github.com/repos/samdark/sitemap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/samdark/sitemap/pulls/55/commits"},"statuses":{"href":"https://api.github.com/repos/samdark/sitemap/statuses/2733b134ae048f5dde0a273c1c2b2c6dce515b4e"}},"author_association":"NONE"}}
{"actor":{"display_login":"samdark"}}