Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
WindSoilder committed Aug 7, 2022
1 parent 30db6d7 commit e9c3ac5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
Binary file removed demo.gif
Binary file not shown.
File renamed without changes.
File renamed without changes
Binary file added examples/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
9 changes: 6 additions & 3 deletions fetcher.nu
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ export def all-libs [] {
}

def get-lib-path [name: string] {
let plugin_dir = (find-lib-path | path dirname)
let plugin_dir = (find-plugin-path | path dirname)
$plugin_dir | path join "reader" $"($name).py"
}

# download binary parsing lib from kaitai gallery
export def fetch-lib [
name: string # lib name
] {
if (not (all-libs | any? ($it == $name))) {
error make -u {msg: $"Library `($name)` is not supported, run `all-libs` to check for all available libs"}
}
echo $"going to download lib ($name)"
let url = $"https://formats.kaitai.io/($name)/src/python/($name).py"
let content = fetch $url
let target_path = get-lib-path $name
echo $"download complete, save it to ($target_path)"
echo $"download complete, begin to save"
$content | save $target_path
echo "done"
}
Expand All @@ -66,7 +69,7 @@ export def remove-lib [

# remove all binary parsing libs
export def remove-all-libs [] {
let plugin_dir = (find-lib-path | path dirname)
let plugin_dir = (find-plugin-path | path dirname)
rm -rf ($plugin_dir | path join "reader" "*")
}

Expand Down
20 changes: 14 additions & 6 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,22 @@ def process_call(plugin_call):


def handle(binary_data, format, span):
if format == "png":
from reader.png import Png
try:
if format == "png":
from reader.png import Png

data = Png(KaitaiStream(BytesIO(binary_data)))
elif format == "ttf":
from reader.ttf import Ttf

data = Ttf(KaitaiStream(BytesIO(binary_data)))

data = Png(KaitaiStream(BytesIO(binary_data)))
elif format == "ttf":
from reader.ttf import Ttf
elif format == "gif":
from reader.gif import Gif

data = Ttf(KaitaiStream(BytesIO(binary_data)))
data = Gif(KaitaiStream(BytesIO(binary_data)))
except ImportError as e:
raise RuntimeError(f"Can't find `{format}` binary reading lib, you should download it first")
a = kaitai_obj_to_dict(data)
return to_nu_value(a, span)

Expand Down

0 comments on commit e9c3ac5

Please sign in to comment.