author | Eric Sunshine
<sunshine@sunshineco.com> 2015-01-13 09:57:13 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2015-01-13 19:51:44 UTC |
parent | 58037e57c591b1c55594a0adb637d1880bfacaee |
git-arr | +1 | -0 |
utils.py | +3 | -0 |
views/blob.html | +8 | -0 |
diff --git a/git-arr b/git-arr index f559af4..d3f1151 100755 --- a/git-arr +++ b/git-arr @@ -187,6 +187,7 @@ def with_utils(f): 'markdown_blob': utils.markdown_blob, 'can_embed_image': utils.can_embed_image, 'embed_image_blob': utils.embed_image_blob, + 'is_binary': utils.is_binary, 'abort': bottle.abort, 'smstr': git.smstr, } diff --git a/utils.py b/utils.py index a68836f..5bea961 100644 --- a/utils.py +++ b/utils.py @@ -103,3 +103,6 @@ def embed_image_blob(fname, image_data): return '<img style="max-width:100%;" src="data:{0};base64,{1}" />'.format( \ mimetype, base64.b64encode(image_data)) +def is_binary(s): + # Git considers a blob binary if NUL in first ~8KB, so do the same. + return '\0' in s[:8192] diff --git a/views/blob.html b/views/blob.html index 1849260..4526c99 100644 --- a/views/blob.html +++ b/views/blob.html @@ -41,6 +41,14 @@ % if can_embed_image(repo, fname.unicode): {{!embed_image_blob(fname.raw, blob.raw_content)}} +% elif is_binary(blob.raw_content): +<table class="nice"> + <tr> + <td> + binary — {{'{:,}'.format(len(blob.raw_content))}} bytes + </td> + </tr> +</table> % elif can_markdown(repo, fname.unicode): {{!markdown_blob(blob.utf8_content)}} % elif can_colorize(blob.utf8_content):