diff --git a/.nushell/binary.nu b/.nushell/binary.nu index 0fb28ee6f437f57bac788c5e18886fae325c5878..2f30ec71138b5209f0a6ee93369d052daeaf10e4 100644 --- a/.nushell/binary.nu +++ b/.nushell/binary.nu @@ -1,16 +1,3 @@ -# decode a list of integer bytes into the underlying encoded string -export def "bytes decode" [encoding: string = "utf-8"]: list<int> -> string { - each { into binary | bytes at 0..1 } | bytes collect | decode $encoding -} - -# encode an encoded string into the underlying list of integer bytes -export def "bytes encode" [encoding: string = "utf-8"]: string -> list<int> { - let bytes = $in | encode $encoding - seq 1 ($bytes | bytes length) | each {|i| - $bytes | bytes at ($i - 1)..($i) | into int - } -} - export def "bytes from_int" []: [int -> binary, list<int> -> binary] { each { into binary --compact } | bytes collect } diff --git a/tests/binary.nu b/tests/binary.nu index 1cb755f6973d16eb5d880a2b8f5ff9f69bf2593e..21a5a736ba76fee4d6f52c1c925ad720558f79d5 100644 --- a/tests/binary.nu +++ b/tests/binary.nu @@ -1,6 +1,4 @@ -use ../.nushell binary [ - "bytes decode", "bytes encode", "bytes from_int", "bytes to_int" -] +use ../.nushell binary [ "bytes from_int", "bytes to_int" ] use std assert @@ -18,8 +16,4 @@ def main [] { let bytes = random-bytes 1_000 assert equal ($bytes | bytes from_int | bytes to_int) $bytes - - const input = "hello world!" - assert equal ($input | bytes encode) $hello_world_int - assert equal ($input | bytes encode | bytes decode) $input }