Skip to content
Snippets Groups Projects
Verified Commit 1bf896e3 authored by STEVAN Antoine's avatar STEVAN Antoine 🦀
Browse files

remove useless binary encode and decode

parent 1f742416
No related branches found
No related tags found
No related merge requests found
Pipeline #5627 passed
This commit is part of merge request !149. Comments created here will be created in the context of that merge request.
# 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] { export def "bytes from_int" []: [int -> binary, list<int> -> binary] {
each { into binary --compact } | bytes collect each { into binary --compact } | bytes collect
} }
......
use ../.nushell binary [ use ../.nushell binary [ "bytes from_int", "bytes to_int" ]
"bytes decode", "bytes encode", "bytes from_int", "bytes to_int"
]
use std assert use std assert
...@@ -18,8 +16,4 @@ def main [] { ...@@ -18,8 +16,4 @@ def main [] {
let bytes = random-bytes 1_000 let bytes = random-bytes 1_000
assert equal ($bytes | bytes from_int | bytes to_int) $bytes 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
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment