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 \blobStr: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:

LetterMeaning
AExtract a string, where each element of the Blob maps to a codepoint
aSame as A
CExtract an element from the blob as an integer
HExtracts a hex string
LExtracts four elements and returns them as a single unsigned integer
nExtracts two elements and combines them in "network" (BigEndian) byte order into a single integer
NExtracts four elements and combines them in "network" (BigEndian) byte order into a single integer
SExtracts two elements and returns them as a single unsigned integer
vSame as S
VSame as L
xDrop an element from the blob (that is, ignore it)
ZSame as A

Example:

use experimental :pack;
say Blob.new(1..10).unpack("C*");
# OUTPUT: «(1 2 3 4 5 6 7 8 9 10)␤»