2022-02-16 19:10:41 +03:00
|
|
|
include "internal";
|
|
|
|
include "options";
|
2022-03-02 20:24:01 +03:00
|
|
|
include "ansi";
|
2022-02-16 19:10:41 +03:00
|
|
|
|
2021-11-29 16:26:42 +03:00
|
|
|
# TODO: error value preview
|
|
|
|
def _expected_decode_value:
|
2022-02-15 01:43:49 +03:00
|
|
|
error("expected decode value but got: \(. | type) (\(. | tostring))");
|
|
|
|
def _is_decode_value: _exttype == "decode_value";
|
|
|
|
|
2021-11-29 16:26:42 +03:00
|
|
|
def _decode_value(f; ef):
|
|
|
|
if _is_decode_value then f
|
|
|
|
else ef
|
|
|
|
end;
|
|
|
|
def _decode_value(f): _decode_value(f; _expected_decode_value);
|
|
|
|
|
2021-11-19 13:44:23 +03:00
|
|
|
# null input means done, otherwise {approx_read_bytes: 123, total_size: 123}
|
|
|
|
# TODO: decode provide even more detailed progress, post-process sort etc?
|
|
|
|
def _decode_progress:
|
|
|
|
# _input_filenames is remaning files to read
|
|
|
|
( (_input_filenames | length) as $inputs_len
|
|
|
|
| ( options.filenames | length) as $filenames_len
|
|
|
|
| _ansi.clear_line
|
|
|
|
, "\r"
|
|
|
|
, if . != null then
|
|
|
|
( if $filenames_len > 1 then
|
|
|
|
"\($filenames_len - $inputs_len)/\($filenames_len) \(_input_filename) "
|
|
|
|
else empty
|
|
|
|
end
|
|
|
|
, "\((.approx_read_bytes / .total_size * 100 | _numbertostring(1)))%"
|
|
|
|
)
|
|
|
|
else empty
|
|
|
|
end
|
2022-01-05 23:36:22 +03:00
|
|
|
| printerr
|
2021-11-19 13:44:23 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
def decode($name; $decode_opts):
|
|
|
|
( options as $opts
|
|
|
|
| _decode(
|
|
|
|
$name;
|
2021-12-09 19:15:21 +03:00
|
|
|
( {
|
|
|
|
_progress: (
|
|
|
|
if $opts.decode_progress and $opts.repl and stdout_tty.is_terminal then
|
|
|
|
"_decode_progress"
|
|
|
|
else null
|
|
|
|
end
|
|
|
|
),
|
|
|
|
}
|
|
|
|
+ $opts
|
|
|
|
+ $decode_opts
|
|
|
|
)
|
2021-11-19 13:44:23 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
def decode($name): decode($name; {});
|
|
|
|
def decode: decode(options.decode_format; {});
|
|
|
|
|
|
|
|
def topath: _decode_value(._path);
|
|
|
|
def tovalue($opts): _tovalue(options($opts));
|
2022-02-07 19:11:51 +03:00
|
|
|
def tovalue: _tovalue(options({}));
|
2021-11-19 13:44:23 +03:00
|
|
|
def toactual: _decode_value(._actual);
|
|
|
|
def tosym: _decode_value(._sym);
|
|
|
|
def todescription: _decode_value(._description);
|
|
|
|
|
|
|
|
# TODO: rename?
|
|
|
|
def format: _decode_value(._format; null);
|
|
|
|
|
2022-03-03 15:37:35 +03:00
|
|
|
def formats:
|
|
|
|
_registry.formats;
|
|
|
|
|
2021-11-19 13:44:23 +03:00
|
|
|
def root: _decode_value(._root);
|
|
|
|
def buffer_root: _decode_value(._buffer_root);
|
|
|
|
def format_root: _decode_value(._format_root);
|
|
|
|
def parent: _decode_value(._parent);
|
|
|
|
def parents:
|
|
|
|
# TODO: refactor, _while_break?
|
|
|
|
( _decode_value(._parent)
|
|
|
|
| if . == null then empty
|
|
|
|
else
|
|
|
|
_recurse_break(
|
|
|
|
( ._parent
|
|
|
|
| if . == null then error("break") end
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
);
|
|
|
|
|
|
|
|
def in_bits_range($p):
|
|
|
|
select(._start <= $p and $p < ._stop);
|
|
|
|
def in_bytes_range($p):
|
|
|
|
select(._start/8 <= $p and $p < ._stop/8);
|