From 9ec936dbfc83dc528cb4fed7c52d46a672db9557 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Mon, 8 Aug 2022 14:23:44 +0800 Subject: [PATCH] rename variable and inner function names, and update README --- README.md | 4 ++-- plugin.py | 4 ++-- utils.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cd7487f..a65a87f 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ A [nushell](https://www.nushell.sh/) plugin to read binary data ## Parsing png and ttf ![parse png and ttf](examples/demo.gif) -## Download lib and parse library +## Download lib and parse binary ![parse gif](examples/demo3.gif) ## Prerequisite @@ -103,7 +103,7 @@ use fetcher.nu fetcher fetch-all-libs ``` -It'll take several minutes to download all binary parsing libs in kaitai gallery. +It'll take several minutes to download all binary parsing libs which exists in kaitai gallery. ## For more references - [Nushell plugin system](https://www.nushell.sh/book/plugins.html) diff --git a/plugin.py b/plugin.py index 0f2f9dc..a472814 100755 --- a/plugin.py +++ b/plugin.py @@ -142,8 +142,8 @@ def handle(binary_data, format, span): reader_class_name = "".join(format.replace("_", " ").title().split(" ")) reader = getattr(module, reader_class_name) data = reader(KaitaiStream(BytesIO(binary_data))) - a = kaitai_obj_to_dict(data) - return to_nu_value(a, span) + py_dict = kaitai_obj_to_dict(data) + return to_nu_value(py_dict, span) def plugin(): diff --git a/utils.py b/utils.py index 95391bd..e0b2f63 100755 --- a/utils.py +++ b/utils.py @@ -15,10 +15,10 @@ def kaitai_obj_to_dict(obj): def to_nu_value(obj, span): - return {"Value": to_nu_value_impl(obj, span)} + return {"Value": _to_nu_value_impl(obj, span)} -def to_nu_value_impl(obj, span): +def _to_nu_value_impl(obj, span): # check for single builtin type. nu_type_table = { str: "String", @@ -34,13 +34,13 @@ def to_nu_value_impl(obj, span): values = [] for k, v in obj.items(): cols.append(k) - values.append(to_nu_value_impl(v, span)) + values.append(_to_nu_value_impl(v, span)) return {"Record": {"cols": cols, "vals": values, "span": span}} # list should convert to List. elif isinstance(obj, list): values = [] for item in obj: - values.append(to_nu_value_impl(item, span)) + values.append(_to_nu_value_impl(item, span)) return {"List": {"vals": values, "span": span}} # bytes should convert to nushell Bytes elif isinstance(obj, (bytes, bytearray)):