diff options
Diffstat (limited to 'stdlib/source/library/lux/data/format/tar.lux')
-rw-r--r-- | stdlib/source/library/lux/data/format/tar.lux | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux index b5627f0b2..13819cdb5 100644 --- a/stdlib/source/library/lux/data/format/tar.lux +++ b/stdlib/source/library/lux/data/format/tar.lux @@ -855,8 +855,8 @@ (n.- |checksum|) (n.+ ..checksum_checksum)))) -(def header_parser - (Parser Header) +(def header_parser/0 + (Parser [Binary [Path Mode ID ID Big Big [Nat Checksum]]]) (function (_ state) (`` (<| (,, (with_template [<binding> <parser>] [(parsed state <binding> <parser>)] @@ -870,10 +870,12 @@ [modification_time ..big_parser] [[actual checksum_code] ..checksum_parser] )) - (let [expected (expected_checksum checksum_code binary_header)]) - (if (not (n.= expected actual)) - (exception.except ..wrong_checksum [expected actual])) - (,, (with_template [<binding> <parser>] + {try.#Success [state [binary_header path mode user_id group_id size modification_time [actual checksum_code]]]})))) + +(def header_parser/1 + (Parser [Link_Flag Path Magic Name Name Device Device]) + (function (_ state) + (`` (<| (,, (with_template [<binding> <parser>] [(parsed state <binding> <parser>)] [link_flag ..link_flag_parser] @@ -885,20 +887,39 @@ [minor_device ..small_parser] [_ (?binary.segment ..header_padding_size)] )) - {try.#Success [state [#path path - #mode mode - #user_id user_id - #group_id group_id - #size size - #modification_time modification_time - #checksum checksum_code - #link_flag link_flag - #link_name link_name - #magic magic - #user_name user_name - #group_name group_name - #major_device major_device - #minor_device minor_device]]})))) + {try.#Success [state [link_flag link_name magic user_name group_name major_device minor_device]]})))) + +(def header_parser + (Parser Header) + (let [phase/1 (all <>.and + ..link_flag_parser + ..path_parser + ..magic_parser + ..name_parser + ..name_parser + ..small_parser + ..small_parser + (?binary.segment ..header_padding_size))] + (function (_ state) + (`` (<| (parsed state [binary_header path mode user_id group_id size modification_time [actual checksum_code]] ..header_parser/0) + (let [expected (expected_checksum checksum_code binary_header)]) + (if (not (n.= expected actual)) + (exception.except ..wrong_checksum [expected actual])) + (parsed state [link_flag link_name magic user_name group_name major_device minor_device] ..header_parser/1) + {try.#Success [state [#path path + #mode mode + #user_id user_id + #group_id group_id + #size size + #modification_time modification_time + #checksum checksum_code + #link_flag link_flag + #link_name link_name + #magic magic + #user_name user_name + #group_name group_name + #major_device major_device + #minor_device minor_device]]}))))) (def (file_parser header) (-> Header |