Skip to content
Snippets Groups Projects
Unverified Commit 9aad77fe authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

add a Nushell module to manipulate bytes as `list<int>`

parent 3ecb46d1
No related branches found
No related tags found
No related merge requests found
# 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
}
}
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