Skip to content

Commit

Permalink
rename variable and inner function names, and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
WindSoilder committed Aug 8, 2022
1 parent 69a180b commit 9ec936d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
8 changes: 4 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)):
Expand Down

0 comments on commit 9ec936d

Please sign in to comment.