{"action":"created","comment":{"url":"https://api.github.com/repos/borgbackup/borg/pulls/comments/42527053","id":42527053,"diff_hunk":"@@ -457,19 +457,26 @@ def x(v):\n     return '%s%s%s' % (x(mod // 64), x(mod // 8), x(mod))\n \n \n-def format_file_size(v):\n+def format_file_size(v, precision=2):\n     \"\"\"Format file size into a human friendly format\n     \"\"\"\n-    if abs(v) > 10**12:\n-        return '%.2f TB' % (v / 10**12)\n-    elif abs(v) > 10**9:\n-        return '%.2f GB' % (v / 10**9)\n-    elif abs(v) > 10**6:\n-        return '%.2f MB' % (v / 10**6)\n-    elif abs(v) > 10**3:\n-        return '%.2f kB' % (v / 10**3)\n-    else:\n-        return '%d B' % v\n+    return sizeof_fmt_decimal(v, suffix='B', sep=' ', precision=precision)\n+\n+def sizeof_fmt(num, suffix='B', units=None, power=None, sep='', precision=2):\n+    for unit in units[:-1]:\n+        if abs(round(num, precision)) < power:\n+            if type(num) is int:\n+                return \"{}{}{}{}\".format(num, sep, unit, suffix)\n+            else:\n+                return \"{:3.{}f}{}{}{}\".format(num, precision, sep, unit, suffix)\n+        num /= float(power)\n+    return \"{:.{}f}{}{}{}\".format(num, precision, sep, units[-1], suffix)\n+\n+def sizeof_fmt_iec(num, suffix='B', sep='', precision=2):\n+   return sizeof_fmt(num, suffix=suffix, sep=sep, precision=precision, units=['','Ki','Mi','Gi','Ti','Pi','Ei','Zi', 'Yi'], power=1024)\n+\n+def sizeof_fmt_decimal(num, suffix='B', sep='', precision=2):\n+   return sizeof_fmt(num, suffix=suffix, sep=sep, precision=precision, units=['','k','M','G','T','P','E','Z', 'Y'], power=1000)","path":"borg/helpers.py","position":34,"original_position":34,"commit_id":"21fdc91995b63ebaec7f4ff6c8b5292212b90d8d","original_commit_id":"21fdc91995b63ebaec7f4ff6c8b5292212b90d8d","user":{"login":"ThomasWaldmann","id":356103,"avatar_url":"https://avatars.githubusercontent.com/u/356103?v=3","gravatar_id":"","url":"https://api.github.com/users/ThomasWaldmann","html_url":"https://github.com/ThomasWaldmann","followers_url":"https://api.github.com/users/ThomasWaldmann/followers","following_url":"https://api.github.com/users/ThomasWaldmann/following{/other_user}","gists_url":"https://api.github.com/users/ThomasWaldmann/gists{/gist_id}","starred_url":"https://api.github.com/users/ThomasWaldmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThomasWaldmann/subscriptions","organizations_url":"https://api.github.com/users/ThomasWaldmann/orgs","repos_url":"https://api.github.com/users/ThomasWaldmann/repos","events_url":"https://api.github.com/users/ThomasWaldmann/events{/privacy}","received_events_url":"https://api.github.com/users/ThomasWaldmann/received_events","type":"User","site_admin":false},"body":"same here","created_at":"2015-10-20T17:33:36Z","updated_at":"2015-10-20T17:33:36Z","html_url":"https://github.com/borgbackup/borg/pull/316#discussion_r42527053","pull_request_url":"https://api.github.com/repos/borgbackup/borg/pulls/316","_links":{"self":{"href":"https://api.github.com/repos/borgbackup/borg/pulls/comments/42527053"},"html":{"href":"https://github.com/borgbackup/borg/pull/316#discussion_r42527053"},"pull_request":{"href":"https://api.github.com/repos/borgbackup/borg/pulls/316"}}},"pull_request":{"url":"https://api.github.com/repos/borgbackup/borg/pulls/316","id":48229650,"html_url":"https://github.com/borgbackup/borg/pull/316","diff_url":"https://github.com/borgbackup/borg/pull/316.diff","patch_url":"https://github.com/borgbackup/borg/pull/316.patch","issue_url":"https://api.github.com/repos/borgbackup/borg/issues/316","number":316,"state":"open","locked":false,"title":"improve file size displays","user":{"login":"anarcat","id":796623,"avatar_url":"https://avatars.githubusercontent.com/u/796623?v=3","gravatar_id":"","url":"https://api.github.com/users/anarcat","html_url":"https://github.com/anarcat","followers_url":"https://api.github.com/users/anarcat/followers","following_url":"https://api.github.com/users/anarcat/following{/other_user}","gists_url":"https://api.github.com/users/anarcat/gists{/gist_id}","starred_url":"https://api.github.com/users/anarcat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anarcat/subscriptions","organizations_url":"https://api.github.com/users/anarcat/orgs","repos_url":"https://api.github.com/users/anarcat/repos","events_url":"https://api.github.com/users/anarcat/events{/privacy}","received_events_url":"https://api.github.com/users/anarcat/received_events","type":"User","site_admin":false},"body":"a number of bugs were discovered while cleaning up the file size code:\r\n\r\n * 1 kB was displayed as 1000 bytes\r\n * there was no support for sizes beyond 1TB\r\n * and some rounding issues as well (999995000 would be displayed as 999.99MB instead of 1GB).\r\n\r\ni have made tests for all of those and more, and refactored the size formatting code so it can support binary prefixes as well, in case we want to report memory usage (which is usually in powers of 2). the code also now support variable precision.\r\n\r\nthis is a fix for #289, provided that i find where in the documentation to explain that we have proper units (aka `k` means 1000, like in SI, otherwise noted). where should that be done?","created_at":"2015-10-20T17:07:12Z","updated_at":"2015-10-20T17:33:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d94a2f059138a88ac32a7c474bc56b050837b4de","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/borgbackup/borg/pulls/316/commits","review_comments_url":"https://api.github.com/repos/borgbackup/borg/pulls/316/comments","review_comment_url":"https://api.github.com/repos/borgbackup/borg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/borgbackup/borg/issues/316/comments","statuses_url":"https://api.github.com/repos/borgbackup/borg/statuses/21fdc91995b63ebaec7f4ff6c8b5292212b90d8d","head":{"label":"anarcat:file-sizes","ref":"file-sizes","sha":"21fdc91995b63ebaec7f4ff6c8b5292212b90d8d","user":{"login":"anarcat","id":796623,"avatar_url":"https://avatars.githubusercontent.com/u/796623?v=3","gravatar_id":"","url":"https://api.github.com/users/anarcat","html_url":"https://github.com/anarcat","followers_url":"https://api.github.com/users/anarcat/followers","following_url":"https://api.github.com/users/anarcat/following{/other_user}","gists_url":"https://api.github.com/users/anarcat/gists{/gist_id}","starred_url":"https://api.github.com/users/anarcat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anarcat/subscriptions","organizations_url":"https://api.github.com/users/anarcat/orgs","repos_url":"https://api.github.com/users/anarcat/repos","events_url":"https://api.github.com/users/anarcat/events{/privacy}","received_events_url":"https://api.github.com/users/anarcat/received_events","type":"User","site_admin":false},"repo":{"id":36046474,"name":"borg","full_name":"anarcat/borg","owner":{"login":"anarcat","id":796623,"avatar_url":"https://avatars.githubusercontent.com/u/796623?v=3","gravatar_id":"","url":"https://api.github.com/users/anarcat","html_url":"https://github.com/anarcat","followers_url":"https://api.github.com/users/anarcat/followers","following_url":"https://api.github.com/users/anarcat/following{/other_user}","gists_url":"https://api.github.com/users/anarcat/gists{/gist_id}","starred_url":"https://api.github.com/users/anarcat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anarcat/subscriptions","organizations_url":"https://api.github.com/users/anarcat/orgs","repos_url":"https://api.github.com/users/anarcat/repos","events_url":"https://api.github.com/users/anarcat/events{/privacy}","received_events_url":"https://api.github.com/users/anarcat/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/anarcat/borg","description":"Deduplicating backup program with compression and authenticated encryption","fork":true,"url":"https://api.github.com/repos/anarcat/borg","forks_url":"https://api.github.com/repos/anarcat/borg/forks","keys_url":"https://api.github.com/repos/anarcat/borg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anarcat/borg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anarcat/borg/teams","hooks_url":"https://api.github.com/repos/anarcat/borg/hooks","issue_events_url":"https://api.github.com/repos/anarcat/borg/issues/events{/number}","events_url":"https://api.github.com/repos/anarcat/borg/events","assignees_url":"https://api.github.com/repos/anarcat/borg/assignees{/user}","branches_url":"https://api.github.com/repos/anarcat/borg/branches{/branch}","tags_url":"https://api.github.com/repos/anarcat/borg/tags","blobs_url":"https://api.github.com/repos/anarcat/borg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anarcat/borg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anarcat/borg/git/refs{/sha}","trees_url":"https://api.github.com/repos/anarcat/borg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anarcat/borg/statuses/{sha}","languages_url":"https://api.github.com/repos/anarcat/borg/languages","stargazers_url":"https://api.github.com/repos/anarcat/borg/stargazers","contributors_url":"https://api.github.com/repos/anarcat/borg/contributors","subscribers_url":"https://api.github.com/repos/anarcat/borg/subscribers","subscription_url":"https://api.github.com/repos/anarcat/borg/subscription","commits_url":"https://api.github.com/repos/anarcat/borg/commits{/sha}","git_commits_url":"https://api.github.com/repos/anarcat/borg/git/commits{/sha}","comments_url":"https://api.github.com/repos/anarcat/borg/comments{/number}","issue_comment_url":"https://api.github.com/repos/anarcat/borg/issues/comments{/number}","contents_url":"https://api.github.com/repos/anarcat/borg/contents/{+path}","compare_url":"https://api.github.com/repos/anarcat/borg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anarcat/borg/merges","archive_url":"https://api.github.com/repos/anarcat/borg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anarcat/borg/downloads","issues_url":"https://api.github.com/repos/anarcat/borg/issues{/number}","pulls_url":"https://api.github.com/repos/anarcat/borg/pulls{/number}","milestones_url":"https://api.github.com/repos/anarcat/borg/milestones{/number}","notifications_url":"https://api.github.com/repos/anarcat/borg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anarcat/borg/labels{/name}","releases_url":"https://api.github.com/repos/anarcat/borg/releases{/id}","created_at":"2015-05-22T01:49:56Z","updated_at":"2015-10-17T06:13:27Z","pushed_at":"2015-10-20T17:04:07Z","git_url":"git://github.com/anarcat/borg.git","ssh_url":"git@github.com:anarcat/borg.git","clone_url":"https://github.com/anarcat/borg.git","svn_url":"https://github.com/anarcat/borg","homepage":"https://borgbackup.github.io/","size":2404,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"logging-refactor"}},"base":{"label":"borgbackup:master","ref":"master","sha":"a4f136afba7c0e3670ed3ff351f3700e92c0505a","user":{"login":"borgbackup","id":12418060,"avatar_url":"https://avatars.githubusercontent.com/u/12418060?v=3","gravatar_id":"","url":"https://api.github.com/users/borgbackup","html_url":"https://github.com/borgbackup","followers_url":"https://api.github.com/users/borgbackup/followers","following_url":"https://api.github.com/users/borgbackup/following{/other_user}","gists_url":"https://api.github.com/users/borgbackup/gists{/gist_id}","starred_url":"https://api.github.com/users/borgbackup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borgbackup/subscriptions","organizations_url":"https://api.github.com/users/borgbackup/orgs","repos_url":"https://api.github.com/users/borgbackup/repos","events_url":"https://api.github.com/users/borgbackup/events{/privacy}","received_events_url":"https://api.github.com/users/borgbackup/received_events","type":"Organization","site_admin":false},"repo":{"id":35517126,"name":"borg","full_name":"borgbackup/borg","owner":{"login":"borgbackup","id":12418060,"avatar_url":"https://avatars.githubusercontent.com/u/12418060?v=3","gravatar_id":"","url":"https://api.github.com/users/borgbackup","html_url":"https://github.com/borgbackup","followers_url":"https://api.github.com/users/borgbackup/followers","following_url":"https://api.github.com/users/borgbackup/following{/other_user}","gists_url":"https://api.github.com/users/borgbackup/gists{/gist_id}","starred_url":"https://api.github.com/users/borgbackup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/borgbackup/subscriptions","organizations_url":"https://api.github.com/users/borgbackup/orgs","repos_url":"https://api.github.com/users/borgbackup/repos","events_url":"https://api.github.com/users/borgbackup/events{/privacy}","received_events_url":"https://api.github.com/users/borgbackup/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/borgbackup/borg","description":"Deduplicating backup program with compression and authenticated encryption.","fork":false,"url":"https://api.github.com/repos/borgbackup/borg","forks_url":"https://api.github.com/repos/borgbackup/borg/forks","keys_url":"https://api.github.com/repos/borgbackup/borg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/borgbackup/borg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/borgbackup/borg/teams","hooks_url":"https://api.github.com/repos/borgbackup/borg/hooks","issue_events_url":"https://api.github.com/repos/borgbackup/borg/issues/events{/number}","events_url":"https://api.github.com/repos/borgbackup/borg/events","assignees_url":"https://api.github.com/repos/borgbackup/borg/assignees{/user}","branches_url":"https://api.github.com/repos/borgbackup/borg/branches{/branch}","tags_url":"https://api.github.com/repos/borgbackup/borg/tags","blobs_url":"https://api.github.com/repos/borgbackup/borg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/borgbackup/borg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/borgbackup/borg/git/refs{/sha}","trees_url":"https://api.github.com/repos/borgbackup/borg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/borgbackup/borg/statuses/{sha}","languages_url":"https://api.github.com/repos/borgbackup/borg/languages","stargazers_url":"https://api.github.com/repos/borgbackup/borg/stargazers","contributors_url":"https://api.github.com/repos/borgbackup/borg/contributors","subscribers_url":"https://api.github.com/repos/borgbackup/borg/subscribers","subscription_url":"https://api.github.com/repos/borgbackup/borg/subscription","commits_url":"https://api.github.com/repos/borgbackup/borg/commits{/sha}","git_commits_url":"https://api.github.com/repos/borgbackup/borg/git/commits{/sha}","comments_url":"https://api.github.com/repos/borgbackup/borg/comments{/number}","issue_comment_url":"https://api.github.com/repos/borgbackup/borg/issues/comments{/number}","contents_url":"https://api.github.com/repos/borgbackup/borg/contents/{+path}","compare_url":"https://api.github.com/repos/borgbackup/borg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/borgbackup/borg/merges","archive_url":"https://api.github.com/repos/borgbackup/borg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/borgbackup/borg/downloads","issues_url":"https://api.github.com/repos/borgbackup/borg/issues{/number}","pulls_url":"https://api.github.com/repos/borgbackup/borg/pulls{/number}","milestones_url":"https://api.github.com/repos/borgbackup/borg/milestones{/number}","notifications_url":"https://api.github.com/repos/borgbackup/borg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/borgbackup/borg/labels{/name}","releases_url":"https://api.github.com/repos/borgbackup/borg/releases{/id}","created_at":"2015-05-12T23:10:47Z","updated_at":"2015-10-18T23:09:31Z","pushed_at":"2015-10-20T17:24:15Z","git_url":"git://github.com/borgbackup/borg.git","ssh_url":"git@github.com:borgbackup/borg.git","clone_url":"https://github.com/borgbackup/borg.git","svn_url":"https://github.com/borgbackup/borg","homepage":"https://borgbackup.github.io/","size":3548,"stargazers_count":143,"watchers_count":143,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":24,"mirror_url":null,"open_issues_count":95,"forks":24,"open_issues":95,"watchers":143,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/borgbackup/borg/pulls/316"},"html":{"href":"https://github.com/borgbackup/borg/pull/316"},"issue":{"href":"https://api.github.com/repos/borgbackup/borg/issues/316"},"comments":{"href":"https://api.github.com/repos/borgbackup/borg/issues/316/comments"},"review_comments":{"href":"https://api.github.com/repos/borgbackup/borg/pulls/316/comments"},"review_comment":{"href":"https://api.github.com/repos/borgbackup/borg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/borgbackup/borg/pulls/316/commits"},"statuses":{"href":"https://api.github.com/repos/borgbackup/borg/statuses/21fdc91995b63ebaec7f4ff6c8b5292212b90d8d"}}}}