Bytes
bytes— Various commands for working with byte data.bytes add— Add specified bytes to the binary input.bytes at— Get bytes from the input defined by a range.bytes build— Create a binary value from the provided arguments.bytes collect— Concatenate multiple binary into a single binary, with an optional separator between each.bytes ends-with— Check if binary data ends with a pattern.bytes index-of— Returns start index of first occurrence of pattern in bytes, or -1 if no match.bytes length— Output the length of any bytes in the pipeline.bytes remove— Remove specified bytes from the input.bytes replace— Find and replace bytes in binary data.bytes reverse— Reverse the bytes in the pipeline.bytes split— Split input into multiple items using a separator.bytes starts-with— Check if binary data starts with a pattern.
Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.
Tips
Intro
bytes length counts binary bytes.
0x[01 02] | bytes length
encode utf8 turns text into bytes.
"ab" | encode utf8
Basic
Count the bytes in a short string.
"hi" | encode utf8 | bytes length
bytes reverse flips the byte order.
0x[01 02 03] | bytes reverse | bytes length
Intermediate
A byte count can become text.
"hi" | encode utf8 | bytes length | into string
Encode each string inside a closure.
["a" "b"] | each {|s| $s | encode utf8} | length
Advanced
Four steps from text to a character count.
"hi" | encode utf8 | bytes length | into string | str length