In role Blob§
See primary documentation in context for routine unpack
This method is considered experimental, in order to use it you will need to do:
use experimental :pack; multi method unpack(Blob:D: Str:D $template) multi method unpack(Blob:D: @template) multi unpack(Blob:D \blob, Str:D $template) multi unpack(Blob:D \blob, @template)
Extracts features from the blob according to the template string, and returns them as a list.
The template string consists of zero or more units that begin with an ASCII letter, and are optionally followed by a quantifier. The quantifier can be *
(which typically stands for "use up the rest of the Blob here"), or a positive integer (without a +
).
Whitespace between template units is ignored.
Examples of valid templates include "A4 C n*"
and "A*"
.
The following letters are recognized:
Letter | Meaning |
---|---|
A | Extract a string, where each element of the Blob maps to a codepoint |
a | Same as 'A' |
C | Extract an element from the blob as an integer |
H | Extracts a hex string |
L | Extracts four elements and returns them as a single unsigned integer |
n | Extracts two elements and combines them in "network" (BigEndian) byte order into a single integer |
N | Extracts four elements and combines them in "network" (BigEndian) byte order into a single integer |
S | Extracts two elements and returns them as a single unsigned integer |
v | Same as 'S' |
V | Same as 'L' |
x | Drop an element from the blob (that is, ignore it) |
Z | Same as 'A' |
Example:
use experimental :pack; say Blob.new(1..10).unpack("C*"); # OUTPUT: «(1 2 3 4 5 6 7 8 9 10)»