diff options
author | Eduardo Julian | 2020-12-25 09:22:38 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-12-25 09:22:38 -0400 |
commit | 4ca397765805eda5ddee393901ed3a02001a960a (patch) | |
tree | 2ab184a1a4e244f3a69e86c8a7bb3ad49c22b4a3 /stdlib/source/lux/data/format/tar.lux | |
parent | d29e091e98dabb8dfcf816899ada480ecbf7e357 (diff) |
Replaced kebab-case with snake_case for naming convention.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/data/format/tar.lux | 660 |
1 files changed, 330 insertions, 330 deletions
diff --git a/stdlib/source/lux/data/format/tar.lux b/stdlib/source/lux/data/format/tar.lux index 0b55a77a2..16b801676 100644 --- a/stdlib/source/lux/data/format/tar.lux +++ b/stdlib/source/lux/data/format/tar.lux @@ -32,29 +32,29 @@ (type: Size Nat) -(def: octal-size Size 8) +(def: octal_size Size 8) -(def: (octal-padding max-size number) +(def: (octal_padding max_size number) (-> Size Text Text) - (let [padding-size (n.- (text.size number) - max-size) + (let [padding_size (n.- (text.size number) + max_size) padding (|> "0" - (list.repeat padding-size) - (text.join-with ""))] + (list.repeat padding_size) + (text.join_with ""))] (format padding number))) (def: blank " ") (def: null text.null) -(def: small-size Size 6) -(def: big-size Size 11) +(def: small_size Size 6) +(def: big_size Size 11) (template [<exception> <limit> <size> <type> <in> <out> <writer> <suffix> <coercion>] [(def: #export <limit> Nat - (|> ..octal-size + (|> ..octal_size (list.repeat <size>) (list\fold n.* 1) inc)) @@ -80,13 +80,13 @@ (def: <writer> (Writer <type>) (let [suffix <suffix> - padded-size (n.+ (text.size suffix) <size>)] + padded_size (n.+ (text.size suffix) <size>)] (|>> :representation (\ n.octal encode) - (..octal-padding <size>) + (..octal_padding <size>) (text.suffix suffix) (\ encoding.utf8 encode) - (format.segment padded-size)))) + (format.segment padded_size)))) (def: <coercion> (-> Nat <type>) @@ -94,53 +94,53 @@ :abstraction)) )] - [not-a-small-number small-limit ..small-size - Small small from-small - small-writer (format ..blank ..null) - coerce-small] - [not-a-big-number big-limit ..big-size - Big big from-big - big-writer ..blank - coerce-big] + [not_a_small_number small_limit ..small_size + Small small from_small + small_writer (format ..blank ..null) + coerce_small] + [not_a_big_number big_limit ..big_size + Big big from_big + big_writer ..blank + coerce_big] ) -(exception: #export (wrong-character {expected Char} {actual Char}) +(exception: #export (wrong_character {expected Char} {actual Char}) (exception.report ["Expected" (%.nat expected)] ["Actual" (%.nat actual)])) -(def: verify-small-suffix +(def: verify_small_suffix (Parser Any) (do <>.monad - [pre-end <b>.bits/8 + [pre_end <b>.bits/8 end <b>.bits/8 _ (let [expected (`` (char (~~ (static ..blank))))] - (<>.assert (exception.construct ..wrong-character [expected pre-end]) - (n.= expected pre-end))) + (<>.assert (exception.construct ..wrong_character [expected pre_end]) + (n.= expected pre_end))) _ (let [expected (`` (char (~~ (static ..null))))] - (<>.assert (exception.construct ..wrong-character [expected end]) + (<>.assert (exception.construct ..wrong_character [expected end]) (n.= expected end)))] (wrap []))) -(def: small-parser +(def: small_parser (Parser Small) (do <>.monad - [digits (<b>.segment ..small-size) + [digits (<b>.segment ..small_size) digits (<>.lift (\ encoding.utf8 decode digits)) - _ ..verify-small-suffix] + _ ..verify_small_suffix] (<>.lift (do {! try.monad} [value (\ n.octal decode digits)] (..small value))))) -(def: big-parser +(def: big_parser (Parser Big) (do <>.monad - [digits (<b>.segment ..big-size) + [digits (<b>.segment ..big_size) digits (<>.lift (\ encoding.utf8 decode digits)) end <b>.bits/8 _ (let [expected (`` (char (~~ (static ..blank))))] - (<>.assert (exception.construct ..wrong-character [expected end]) + (<>.assert (exception.construct ..wrong_character [expected end]) (n.= expected end)))] (<>.lift (do {! try.monad} @@ -150,58 +150,58 @@ (abstract: Checksum Text - (def: from-checksum + (def: from_checksum (-> Checksum Text) (|>> :representation)) - (def: dummy-checksum + (def: dummy_checksum Checksum (:abstraction " ")) - (def: checksum-suffix + (def: checksum_suffix (format ..blank ..null)) (def: checksum (-> Binary Nat) (binary.fold n.+ 0)) - (def: checksum-checksum - (|> ..dummy-checksum + (def: checksum_checksum + (|> ..dummy_checksum :representation (\ encoding.utf8 encode) ..checksum)) - (def: checksum-code + (def: checksum_code (-> Binary Checksum) (|>> ..checksum - ..coerce-small - ..from-small + ..coerce_small + ..from_small (\ n.octal encode) - (..octal-padding ..small-size) - (text.suffix ..checksum-suffix) + (..octal_padding ..small_size) + (text.suffix ..checksum_suffix) :abstraction)) - (def: checksum-writer + (def: checksum_writer (Writer Checksum) - (let [padded-size (n.+ (text.size ..checksum-suffix) - ..small-size)] + (let [padded_size (n.+ (text.size ..checksum_suffix) + ..small_size)] (|>> :representation (\ encoding.utf8 encode) - (format.segment padded-size)))) + (format.segment padded_size)))) - (def: checksum-parser + (def: checksum_parser (Parser [Nat Checksum]) (do <>.monad - [ascii (<b>.segment ..small-size) + [ascii (<b>.segment ..small_size) digits (<>.lift (\ encoding.utf8 decode ascii)) - _ ..verify-small-suffix + _ ..verify_small_suffix value (<>.lift (\ n.octal decode digits))] (wrap [value - (:abstraction (format digits ..checksum-suffix))]))) + (:abstraction (format digits ..checksum_suffix))]))) ) -(def: last-ascii +(def: last_ascii Char (number.hex "007F")) @@ -210,17 +210,17 @@ (|>> (\ encoding.utf8 encode) (binary.fold (function (_ char verdict) (.and verdict - (n.<= ..last-ascii char))) + (n.<= ..last_ascii char))) true))) -(exception: #export (not-ascii {text Text}) +(exception: #export (not_ascii {text Text}) (exception.report ["Text" (%.text text)])) -(def: #export name-size Size 31) -(def: #export path-size Size 99) +(def: #export name_size Size 31) +(def: #export path_size Size 99) -(def: (un-pad string) +(def: (un_pad string) (-> Binary (Try Binary)) (case (binary.size string) 0 (#try.Success string) @@ -228,8 +228,8 @@ (case end 0 (#try.Success (\ encoding.utf8 encode "")) _ (do try.monad - [last-char (binary.read/8 end string)] - (`` (case (.nat last-char) + [last_char (binary.read/8 end string)] + (`` (case (.nat last_char) (^ (char (~~ (static ..null)))) (recur (dec end)) @@ -252,7 +252,7 @@ (if (|> value (\ encoding.utf8 encode) binary.size (n.<= <size>)) (#try.Success (:abstraction value)) (exception.throw <exception> [value])) - (exception.throw ..not-ascii [value]))) + (exception.throw ..not_ascii [value]))) (def: #export <out> (-> <type> <representation>) @@ -261,11 +261,11 @@ (def: <writer> (Writer <type>) (let [suffix ..null - padded-size (n.+ (text.size suffix) <size>)] + padded_size (n.+ (text.size suffix) <size>)] (|>> :representation (text.suffix suffix) (\ encoding.utf8 encode) - (format.segment padded-size)))) + (format.segment padded_size)))) (def: <parser> (Parser <type>) @@ -273,11 +273,11 @@ [string (<b>.segment <size>) end <b>.bits/8 #let [expected (`` (char (~~ (static ..null))))] - _ (<>.assert (exception.construct ..wrong-character [expected end]) + _ (<>.assert (exception.construct ..wrong_character [expected end]) (n.= expected end))] (<>.lift (do {! try.monad} - [ascii (..un-pad string) + [ascii (..un_pad string) text (\ encoding.utf8 decode ascii)] (<in> text))))) @@ -286,114 +286,114 @@ (try.assume (<in> ""))) )] - [Name Text ..name-size name-is-too-long name from-name name-writer name-parser anonymous] - [Path file.Path ..path-size path-is-too-long path from-path path-writer path-parser no-path] + [Name Text ..name_size name_is_too_long name from_name name_writer name_parser anonymous] + [Path file.Path ..path_size path_is_too_long path from_path path_writer path_parser no_path] ) -(def: magic-size Size 7) +(def: magic_size Size 7) (abstract: Magic Text (def: ustar (:abstraction "ustar ")) - (def: from-magic + (def: from_magic (-> Magic Text) (|>> :representation)) - (def: magic-writer + (def: magic_writer (Writer Magic) - (let [padded-size (n.+ (text.size ..null) - ..magic-size)] + (let [padded_size (n.+ (text.size ..null) + ..magic_size)] (|>> :representation (\ encoding.utf8 encode) - (format.segment padded-size)))) + (format.segment padded_size)))) - (def: magic-parser + (def: magic_parser (Parser Magic) (do <>.monad - [string (<b>.segment ..magic-size) + [string (<b>.segment ..magic_size) end <b>.bits/8 #let [expected (`` (char (~~ (static ..null))))] - _ (<>.assert (exception.construct ..wrong-character [expected end]) + _ (<>.assert (exception.construct ..wrong_character [expected end]) (n.= expected end))] (<>.lift (\ try.monad map (|>> :abstraction) (\ encoding.utf8 decode string))))) ) -(def: block-size Size 512) +(def: block_size Size 512) -(def: owner-id-size ..small-size) +(def: owner_id_size ..small_size) -(def: blank-size Size (text.size ..blank)) -(def: null-size Size (text.size ..null)) -(def: mode-size Size ..small-size) -(def: content-size Size ..big-size) -(def: modification-time-size Size ..big-size) -(def: checksum-size Size ..small-size) -(def: link-flag-size Size 1) -(def: device-size Size ..small-size) +(def: blank_size Size (text.size ..blank)) +(def: null_size Size (text.size ..null)) +(def: mode_size Size ..small_size) +(def: content_size Size ..big_size) +(def: modification_time_size Size ..big_size) +(def: checksum_size Size ..small_size) +(def: link_flag_size Size 1) +(def: device_size Size ..small_size) -(def: small-number +(def: small_number (-> Size Size) - (|>> ($_ n.+ ..blank-size ..null-size))) + (|>> ($_ n.+ ..blank_size ..null_size))) -(def: big-number +(def: big_number (-> Size Size) - (|>> ($_ n.+ ..blank-size))) + (|>> ($_ n.+ ..blank_size))) (def: string (-> Size Size) - (|>> ($_ n.+ ..null-size))) + (|>> ($_ n.+ ..null_size))) -(def: header-size +(def: header_size ($_ n.+ ## name - (..string ..path-size) + (..string ..path_size) ## mode - (..small-number ..mode-size) + (..small_number ..mode_size) ## uid - (..small-number ..owner-id-size) + (..small_number ..owner_id_size) ## gid - (..small-number ..owner-id-size) + (..small_number ..owner_id_size) ## size - (..big-number ..content-size) + (..big_number ..content_size) ## mtime - (..big-number ..modification-time-size) + (..big_number ..modification_time_size) ## chksum - (..small-number ..checksum-size) + (..small_number ..checksum_size) ## linkflag - ..link-flag-size + ..link_flag_size ## linkname - (..string ..path-size) + (..string ..path_size) ## magic - (..string ..magic-size) + (..string ..magic_size) ## uname - (..string ..name-size) + (..string ..name_size) ## gname - (..string ..name-size) + (..string ..name_size) ## devmajor - (..small-number ..device-size) + (..small_number ..device_size) ## devminor - (..small-number ..device-size))) + (..small_number ..device_size))) -(abstract: Link-Flag +(abstract: Link_Flag Char - (def: link-flag - (-> Link-Flag Char) + (def: link_flag + (-> Link_Flag Char) (|>> :representation)) - (def: link-flag-writer - (Writer Link-Flag) + (def: link_flag_writer + (Writer Link_Flag) (|>> :representation format.bits/8)) - (with-expansions [<options> (as-is [0 old-normal] + (with_expansions [<options> (as_is [0 old_normal] [(char "0") normal] [(char "1") link] - [(char "2") symbolic-link] + [(char "2") symbolic_link] [(char "3") character] [(char "4") block] [(char "5") directory] @@ -401,29 +401,29 @@ [(char "7") contiguous])] (template [<flag> <name>] [(def: <name> - Link-Flag + Link_Flag (:abstraction <flag>))] <options> ) - (exception: #export (invalid-link-flag {value Nat}) + (exception: #export (invalid_link_flag {value Nat}) (exception.report ["Value" (%.nat value)])) - (def: link-flag-parser - (Parser Link-Flag) + (def: link_flag_parser + (Parser Link_Flag) (do <>.monad [linkflag <b>.bits/8] (case (.nat linkflag) - (^template [<value> <link-flag>] + (^template [<value> <link_flag>] [(^ <value>) - (wrap <link-flag>)]) + (wrap <link_flag>)]) (<options>) _ (<>.lift - (exception.throw ..invalid-link-flag [(.nat linkflag)])))))) + (exception.throw ..invalid_link_flag [(.nat linkflag)])))))) ) (abstract: #export Mode @@ -439,34 +439,34 @@ (i64.or (:representation left) (:representation right)))) - (def: mode-writer + (def: mode_writer (Writer Mode) (|>> :representation ..small try.assume - ..small-writer)) + ..small_writer)) - (exception: #export (invalid-mode {value Nat}) + (exception: #export (invalid_mode {value Nat}) (exception.report ["Value" (%.nat value)])) - (with-expansions [<options> (as-is ["0000" none] + (with_expansions [<options> (as_is ["0000" none] - ["0001" execute-by-other] - ["0002" write-by-other] - ["0004" read-by-other] + ["0001" execute_by_other] + ["0002" write_by_other] + ["0004" read_by_other] - ["0010" execute-by-group] - ["0020" write-by-group] - ["0040" read-by-group] + ["0010" execute_by_group] + ["0020" write_by_group] + ["0040" read_by_group] - ["0100" execute-by-owner] - ["0200" write-by-owner] - ["0400" read-by-owner] + ["0100" execute_by_owner] + ["0200" write_by_owner] + ["0400" read_by_owner] - ["1000" save-text] - ["2000" set-group-id-on-execution] - ["4000" set-user-id-on-execution])] + ["1000" save_text] + ["2000" set_group_id_on_execution] + ["4000" set_user_id_on_execution])] (template [<code> <name>] [(def: #export <name> Mode @@ -475,43 +475,43 @@ <options> ) - (def: maximum-mode + (def: maximum_mode Mode ($_ and ..none - ..execute-by-other - ..write-by-other - ..read-by-other + ..execute_by_other + ..write_by_other + ..read_by_other - ..execute-by-group - ..write-by-group - ..read-by-group + ..execute_by_group + ..write_by_group + ..read_by_group - ..execute-by-owner - ..write-by-owner - ..read-by-owner + ..execute_by_owner + ..write_by_owner + ..read_by_owner - ..save-text - ..set-group-id-on-execution - ..set-user-id-on-execution + ..save_text + ..set_group_id_on_execution + ..set_user_id_on_execution )) - (def: mode-parser + (def: mode_parser (Parser Mode) (do {! <>.monad} - [value (\ ! map ..from-small ..small-parser)] - (if (n.<= (:representation ..maximum-mode) + [value (\ ! map ..from_small ..small_parser)] + (if (n.<= (:representation ..maximum_mode) value) (wrap (:abstraction value)) (<>.lift - (exception.throw ..invalid-mode [value])))))) + (exception.throw ..invalid_mode [value])))))) ) -(def: maximum-content-size +(def: maximum_content_size Nat - (|> ..octal-size - (list.repeat ..content-size) + (|> ..octal_size + (list.repeat ..content_size) (list\fold n.* 1))) (abstract: #export Content @@ -523,7 +523,7 @@ [size (..big (binary.size content))] (wrap (:abstraction [size content])))) - (def: from-content + (def: from_content (-> Content [Big Binary]) (|>> :representation)) @@ -535,9 +535,9 @@ (type: #export ID Small) -(def: #export no-id +(def: #export no_id ID - (..coerce-small 0)) + (..coerce_small 0)) (type: #export Owner {#name Name @@ -551,20 +551,20 @@ [Path Instant Mode Ownership Content]) (type: #export Normal File) -(type: #export Symbolic-Link Path) +(type: #export Symbolic_Link Path) (type: #export Directory Path) (type: #export Contiguous File) (type: #export Entry (#Normal ..Normal) - (#Symbolic-Link ..Symbolic-Link) + (#Symbolic_Link ..Symbolic_Link) (#Directory ..Directory) (#Contiguous ..Contiguous)) (type: #export Device Small) -(def: no-device +(def: no_device Device (try.assume (..small 0))) @@ -573,163 +573,163 @@ (def: (blocks size) (-> Big Nat) - (n.+ (n./ ..block-size - (..from-big size)) - (case (n.% ..block-size (..from-big size)) + (n.+ (n./ ..block_size + (..from_big size)) + (case (n.% ..block_size (..from_big size)) 0 0 _ 1))) -(def: rounded-content-size +(def: rounded_content_size (-> Big Nat) (|>> ..blocks - (n.* ..block-size))) + (n.* ..block_size))) (type: Header {#path Path #mode Mode - #user-id ID - #group-id ID + #user_id ID + #group_id ID #size Big - #modification-time Big + #modification_time Big #checksum Checksum - #link-flag Link-Flag - #link-name Path + #link_flag Link_Flag + #link_name Path #magic Magic - #user-name Name - #group-name Name - #major-device Device - #minor-device Device}) + #user_name Name + #group_name Name + #major_device Device + #minor_device Device}) -(def: header-writer' +(def: header_writer' (Writer Header) ($_ format.and - ..path-writer - ..mode-writer - ..small-writer - ..small-writer - ..big-writer - ..big-writer - ..checksum-writer - ..link-flag-writer - ..path-writer - ..magic-writer - ..name-writer - ..name-writer - ..small-writer - ..small-writer + ..path_writer + ..mode_writer + ..small_writer + ..small_writer + ..big_writer + ..big_writer + ..checksum_writer + ..link_flag_writer + ..path_writer + ..magic_writer + ..name_writer + ..name_writer + ..small_writer + ..small_writer )) -(def: (header-writer header) +(def: (header_writer header) (Writer Header) (let [checksum (|> header - (set@ #checksum ..dummy-checksum) - (format.run ..header-writer') - ..checksum-code)] + (set@ #checksum ..dummy_checksum) + (format.run ..header_writer') + ..checksum_code)] (|> header (set@ #checksum checksum) - (format.run ..header-writer') - (format.segment ..block-size)))) + (format.run ..header_writer') + (format.segment ..block_size)))) -(def: modification-time +(def: modification_time (-> Instant Big) (|>> instant.relative (duration.query duration.second) .nat - ..coerce-big)) + ..coerce_big)) -(def: (file-writer link-flag) - (-> Link-Flag (Writer File)) - (function (_ [path modification-time mode ownership content]) - (let [[size content] (..from-content content) +(def: (file_writer link_flag) + (-> Link_Flag (Writer File)) + (function (_ [path modification_time mode ownership content]) + (let [[size content] (..from_content content) writer ($_ format.and - ..header-writer - (format.segment (..rounded-content-size size)))] + ..header_writer + (format.segment (..rounded_content_size size)))] (writer [{#path path #mode mode - #user-id (get@ [#user #id] ownership) - #group-id (get@ [#group #id] ownership) + #user_id (get@ [#user #id] ownership) + #group_id (get@ [#group #id] ownership) #size size - #modification-time (..modification-time modification-time) - #checksum ..dummy-checksum - #link-flag link-flag - #link-name ..no-path + #modification_time (..modification_time modification_time) + #checksum ..dummy_checksum + #link_flag link_flag + #link_name ..no_path #magic ..ustar - #user-name (get@ [#user #name] ownership) - #group-name (get@ [#group #name] ownership) - #major-device ..no-device - #minor-device ..no-device} + #user_name (get@ [#user #name] ownership) + #group_name (get@ [#group #name] ownership) + #major_device ..no_device + #minor_device ..no_device} content])))) -(def: normal-file-writer +(def: normal_file_writer (Writer File) - (..file-writer ..normal)) + (..file_writer ..normal)) -(def: contiguous-file-writer +(def: contiguous_file_writer (Writer File) - (..file-writer ..contiguous)) + (..file_writer ..contiguous)) -(def: (symbolic-link-writer path) +(def: (symbolic_link_writer path) (Writer Path) - (..header-writer - {#path ..no-path + (..header_writer + {#path ..no_path #mode ..none - #user-id ..no-id - #group-id ..no-id - #size (..coerce-big 0) - #modification-time (..coerce-big 0) - #checksum ..dummy-checksum - #link-flag ..symbolic-link - #link-name path + #user_id ..no_id + #group_id ..no_id + #size (..coerce_big 0) + #modification_time (..coerce_big 0) + #checksum ..dummy_checksum + #link_flag ..symbolic_link + #link_name path #magic ..ustar - #user-name ..anonymous - #group-name ..anonymous - #major-device ..no-device - #minor-device ..no-device})) + #user_name ..anonymous + #group_name ..anonymous + #major_device ..no_device + #minor_device ..no_device})) -(def: (directory-writer path) +(def: (directory_writer path) (Writer Path) - (..header-writer + (..header_writer {#path path #mode ..none - #user-id ..no-id - #group-id ..no-id - #size (..coerce-big 0) - #modification-time (..coerce-big 0) - #checksum ..dummy-checksum - #link-flag ..directory - #link-name ..no-path + #user_id ..no_id + #group_id ..no_id + #size (..coerce_big 0) + #modification_time (..coerce_big 0) + #checksum ..dummy_checksum + #link_flag ..directory + #link_name ..no_path #magic ..ustar - #user-name ..anonymous - #group-name ..anonymous - #major-device ..no-device - #minor-device ..no-device})) + #user_name ..anonymous + #group_name ..anonymous + #major_device ..no_device + #minor_device ..no_device})) -(def: entry-writer +(def: entry_writer (Writer Entry) - (|>> (case> (#Normal value) (..normal-file-writer value) - (#Symbolic-Link value) (..symbolic-link-writer value) - (#Directory value) (..directory-writer value) - (#Contiguous value) (..contiguous-file-writer value)))) + (|>> (case> (#Normal value) (..normal_file_writer value) + (#Symbolic_Link value) (..symbolic_link_writer value) + (#Directory value) (..directory_writer value) + (#Contiguous value) (..contiguous_file_writer value)))) -(def: end-of-archive-size Size (n.* 2 ..block-size)) +(def: end_of_archive_size Size (n.* 2 ..block_size)) (def: #export writer (Writer Tar) - (let [end-of-archive (binary.create ..end-of-archive-size)] + (let [end_of_archive (binary.create ..end_of_archive_size)] (function (_ tar) (format\compose (row\fold (function (_ next total) - (format\compose total (..entry-writer next))) + (format\compose total (..entry_writer next))) format\identity tar) - (format.segment ..end-of-archive-size end-of-archive))))) + (format.segment ..end_of_archive_size end_of_archive))))) -(exception: #export (wrong-checksum {expected Nat} {actual Nat}) +(exception: #export (wrong_checksum {expected Nat} {actual Nat}) (exception.report ["Expected" (%.nat expected)] ["Actual" (%.nat actual)])) -(def: header-padding-size - (n.- header-size block-size)) +(def: header_padding_size + (n.- header_size block_size)) ## When the checksum gets originally calculated, the assumption is that all the characters in the checksum field ## of the header will be spaces. @@ -737,132 +737,132 @@ ## an incorrect result, as the contents of the checksum field would be an actual checksum, instead of just spaces. ## To correct for this, it is necessary to calculate the checksum of just the checksum field, subtract that, and then ## add-in the checksum of the spaces. -(def: (expected-checksum checksum header) +(def: (expected_checksum checksum header) (-> Checksum Binary Nat) (let [|checksum| (|> checksum - ..from-checksum + ..from_checksum (\ encoding.utf8 encode) ..checksum)] (|> (..checksum header) (n.- |checksum|) - (n.+ ..checksum-checksum)))) + (n.+ ..checksum_checksum)))) -(def: header-parser +(def: header_parser (Parser Header) (do <>.monad - [binary-header (<>.speculative (<b>.segment block-size)) - path ..path-parser - mode ..mode-parser - user-id ..small-parser - group-id ..small-parser - size ..big-parser - modification-time ..big-parser - [actual checksum-code] ..checksum-parser - _ (let [expected (expected-checksum checksum-code binary-header)] + [binary_header (<>.speculative (<b>.segment block_size)) + path ..path_parser + mode ..mode_parser + user_id ..small_parser + group_id ..small_parser + size ..big_parser + modification_time ..big_parser + [actual checksum_code] ..checksum_parser + _ (let [expected (expected_checksum checksum_code binary_header)] (<>.lift - (exception.assert ..wrong-checksum [expected actual] + (exception.assert ..wrong_checksum [expected actual] (n.= expected actual)))) - link-flag ..link-flag-parser - link-name ..path-parser - magic ..magic-parser - user-name ..name-parser - group-name ..name-parser - major-device ..small-parser - minor-device ..small-parser - _ (<b>.segment ..header-padding-size)] + link_flag ..link_flag_parser + link_name ..path_parser + magic ..magic_parser + user_name ..name_parser + group_name ..name_parser + major_device ..small_parser + minor_device ..small_parser + _ (<b>.segment ..header_padding_size)] (wrap {#path path #mode mode - #user-id user-id - #group-id group-id + #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 + #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}))) + #user_name user_name + #group_name group_name + #major_device major_device + #minor_device minor_device}))) -(exception: #export (wrong-link-flag {expected Link-Flag} {actual Link-Flag}) +(exception: #export (wrong_link_flag {expected Link_Flag} {actual Link_Flag}) (exception.report - ["Expected" (%.nat (..link-flag expected))] - ["Actual" (%.nat (..link-flag actual))])) + ["Expected" (%.nat (..link_flag expected))] + ["Actual" (%.nat (..link_flag actual))])) -(def: (file-parser expected) - (-> Link-Flag (Parser File)) +(def: (file_parser expected) + (-> Link_Flag (Parser File)) (do <>.monad - [header ..header-parser - _ (<>.assert (exception.construct ..wrong-link-flag [expected (get@ #link-flag header)]) - (is? expected (get@ #link-flag header))) + [header ..header_parser + _ (<>.assert (exception.construct ..wrong_link_flag [expected (get@ #link_flag header)]) + (is? expected (get@ #link_flag header))) #let [size (get@ #size header) - rounded-size (..rounded-content-size size)] - content (<b>.segment (..from-big size)) + rounded_size (..rounded_content_size size)] + content (<b>.segment (..from_big size)) content (<>.lift (..content content)) - _ (<b>.segment (n.- (..from-big size) rounded-size))] + _ (<b>.segment (n.- (..from_big size) rounded_size))] (wrap [(get@ #path header) (|> header - (get@ #modification-time) - ..from-big + (get@ #modification_time) + ..from_big .int - duration.from-millis - (duration.scale-up (|> duration.second duration.to-millis .nat)) + duration.from_millis + (duration.scale_up (|> duration.second duration.to_millis .nat)) instant.absolute) (get@ #mode header) - {#user {#name (get@ #user-name header) - #id (get@ #user-id header)} - #group {#name (get@ #group-name header) - #id (get@ #group-id header)}} + {#user {#name (get@ #user_name header) + #id (get@ #user_id header)} + #group {#name (get@ #group_name header) + #id (get@ #group_id header)}} content]))) -(def: (file-name-parser expected extractor) - (-> Link-Flag (-> Header Path) (Parser Path)) +(def: (file_name_parser expected extractor) + (-> Link_Flag (-> Header Path) (Parser Path)) (do <>.monad - [header ..header-parser + [header ..header_parser _ (<>.lift - (exception.assert ..wrong-link-flag [expected (get@ #link-flag header)] - (n.= (..link-flag expected) - (..link-flag (get@ #link-flag header)))))] + (exception.assert ..wrong_link_flag [expected (get@ #link_flag header)] + (n.= (..link_flag expected) + (..link_flag (get@ #link_flag header)))))] (wrap (extractor header)))) -(def: entry-parser +(def: entry_parser (Parser Entry) ($_ <>.either (\ <>.monad map (|>> #..Normal) - (<>.either (..file-parser ..normal) - (..file-parser ..old-normal))) - (\ <>.monad map (|>> #..Symbolic-Link) - (..file-name-parser ..symbolic-link (get@ #link-name))) + (<>.either (..file_parser ..normal) + (..file_parser ..old_normal))) + (\ <>.monad map (|>> #..Symbolic_Link) + (..file_name_parser ..symbolic_link (get@ #link_name))) (\ <>.monad map (|>> #..Directory) - (..file-name-parser ..directory (get@ #path))) + (..file_name_parser ..directory (get@ #path))) (\ <>.monad map (|>> #..Contiguous) - (..file-parser ..contiguous)))) + (..file_parser ..contiguous)))) ## It's safe to implement the parser this way because the range of values for Nat is 2^64 ## Whereas the maximum possible value for the checksum of a 512 block is (256 × 512) = 131,072 -(def: end-of-archive-block-parser +(def: end_of_archive_block_parser (Parser Any) (do <>.monad - [block (<b>.segment ..block-size)] + [block (<b>.segment ..block_size)] (let [actual (..checksum block)] (<>.lift - (exception.assert ..wrong-checksum [0 actual] + (exception.assert ..wrong_checksum [0 actual] (n.= 0 actual)))))) -(exception: #export invalid-end-of-archive) +(exception: #export invalid_end_of_archive) -(def: end-of-archive-parser +(def: end_of_archive_parser (Parser Any) (do <>.monad - [_ (<>.at-most 2 end-of-archive-block-parser) + [_ (<>.at_most 2 end_of_archive_block_parser) done? <b>.end?] (<>.lift - (exception.assert ..invalid-end-of-archive [] + (exception.assert ..invalid_end_of_archive [] done?)))) (def: #export parser (Parser Tar) - (|> (<>.some entry-parser) - (\ <>.monad map row.from-list) - (<>.before ..end-of-archive-parser))) + (|> (<>.some entry_parser) + (\ <>.monad map row.from_list) + (<>.before ..end_of_archive_parser))) |