Git Product home page Git Product logo

datasette-render-binary's Introduction

datasette-render-binary

PyPI Changelog Tests License

Datasette plugin for rendering binary data.

Install this plugin in the same environment as Datasette to enable this new functionality:

pip install datasette-render-binary

Binary data in cells will now be rendered as a mixture of characters and octets.

Screenshot

datasette-render-binary's People

Contributors

simonw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

datasette-render-binary's Issues

bplist support

Found this prototype, not sure what it's missing though as I don't remember writing it in the first place!

diff --git a/datasette_render_binary/__init__.py b/datasette_render_binary/__init__.py
index 4ce5510..0c86d0d 100644
--- a/datasette_render_binary/__init__.py
+++ b/datasette_render_binary/__init__.py
@@ -1,5 +1,7 @@
 import re
 import filetype
+from filetype.types.base import Type
+from filetype.types import TYPES
 from datasette import hookimpl
 import jinja2
 
@@ -7,13 +9,24 @@ sequence_re = re.compile(r"((?:\\x[0-9a-f]{2})+)")
 octet_re = re.compile(r"(\\x[0-9a-f]{2})")
 
 
+class BpList(Type):
+    MIME = "application/x-plist"
+    EXTENSION = "bplist"
+
+    def __init__(self):
+        super(BpList, self).__init__(mime=BpList.MIME, extension=BpList.EXTENSION)
+
+    def match(self, buf):
+        return len(buf) > 20 and buf.startswith(b"bplist00")
+
+
 @hookimpl(trylast=True)
 def render_cell(value):
     if not isinstance(value, bytes):
         return None
     # Attempt to guess filetype
     suggestion = None
-    match = filetype.guess(value[:1000])
+    match = filetype.match(value[:1000], matchers=TYPES + [BpList()])
     if match:
         suggestion = "{} ({})".format(match.extension, match.mime)
     encoded = repr(value)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.