blob: cap amount of rendered binary blob content

Although hexdump(1)-style rendering of binary blob content may reveal
some meaningful information about the data, it wastes even more storage
space than embedding the raw data itself. However, many binary files
have a "magic number" or other signature near the beginning of the file,
so it is often possible to glean useful information from just the
initial chunk of the file without having the entire content available.

Thus, limiting the rendered data to just an initial chunk saves storage
space while still potentially presenting useful information about the
binary content.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
This commit is contained in:
Eric Sunshine 2015-01-13 04:57:15 -05:00 committed by Alberto Bertogli
parent 6f3942ce38
commit c91beccdb0
2 changed files with 14 additions and 1 deletions

@ -171,6 +171,10 @@ table.blob-binary .offset {
border-right: 1px solid #eee; border-right: 1px solid #eee;
} }
table.blob-binary tr.etc {
text-align: center;
}
/* Pygments overrides. */ /* Pygments overrides. */
div.linenodiv { div.linenodiv {
padding-right: 0.5em; padding-right: 0.5em;

@ -48,7 +48,8 @@
binary &mdash; {{'{:,}'.format(len(blob.raw_content))}} bytes binary &mdash; {{'{:,}'.format(len(blob.raw_content))}} bytes
</td> </td>
</tr> </tr>
% for offset, hex1, hex2, text in hexdump(blob.raw_content): % lim = 256
% for offset, hex1, hex2, text in hexdump(blob.raw_content[:lim]):
<tr> <tr>
<td class="offset">{{offset}}</td> <td class="offset">{{offset}}</td>
<td><pre>{{hex1}}</pre></td> <td><pre>{{hex1}}</pre></td>
@ -56,6 +57,14 @@
<td><pre>{{text}}</pre></td> <td><pre>{{text}}</pre></td>
</tr> </tr>
% end % end
% if lim < len(blob.raw_content):
<tr class="etc">
<td></td>
<td>&hellip;</td>
<td>&hellip;</td>
<td>&hellip;</td>
</tr>
% end
</table> </table>
% elif can_markdown(repo, fname.unicode): % elif can_markdown(repo, fname.unicode):
{{!markdown_blob(blob.utf8_content)}} {{!markdown_blob(blob.utf8_content)}}