In-memory binary data terms
Release: |
4.6 • 5.0 • 5.1 • 5.2 • 5.3 • 5.4 • 6.0 • 6.1 • 6.2 • 6.3 • 6.4 • 6.5 |
---|
Binary data terms (or "blobs")
Sometimes it's useful to hold some arbitrary raw, binary data in memory because of its compactness and speed of reading or writing. The downside is that you can't easily interpret binary data. Such an in-memory block is sometimes called a "blob". The more formal name is a binary data term.
A binary data term is just a block of memory with arbitrary data. Often it's an in-memory copy of a binary file. This can be useful when your code makes many individual reads from different locations in the file, since it avoids repeated file-open and file-close operations, and accesses everything in memory. Sometimes the in-memory image is a portion of a binary file.
Creating a binary data term in memory
The following are ways in which a binary data term can be created.
- A base64 literal, e.g.,
base64'uC8AMcjLQA=='
- A base16 literal, e.g.,
base16'b82f0031c8cb40'
WriteBinaryFile("<>", ...)
ReadBinaryFile( filename, typeFlags:7 )
GetFromBinaryData(..., typeFlags:7)
WriteImageFile( "<>", ...)
ReadProtoBufFile
-- experimental non-supported function
Note that functions that read or write to external sources (files) require Analytica Enterprise or better.
Reading the contents of an in-memory binary data term
BinaryDataSize(data)
-- returns the number of bytesGetFromBinaryData(...)
ParseProtoBuf
-- experimental, non-supported function
Generally when you are reading a piece of information from the blob, you'll want to interpret the contents in some way. The parameters of GetFromBinaryData enable you to control this interpretation so that you can read as different non-opaque data types.
Conversions
This table summarizes various data transformations to and from binary data formats that you might need.
From | To | Method | Required release |
---|---|---|---|
binary file (or part of) | binary data term | ReadBinaryFile | Analytica 6.2 |
binary data term (or part of) | Binary file | WriteBinaryFile | Analytica 6.2 |
part of binary data term | another binary data term | GetFromBinaryData(...typeFlags:7) |
Analytica 6.2 |
image file | binary data term | ReadBinaryFile(filename,typeFlags:7) |
Analytica 6.4 |
in-memory image | binary data term | WriteImageFile("<>", image) |
Analytica 6.4 |
binary data term | image file | WriteBinaryFile(...,typeflags:7) The binary data must contain the bytes for a valid image. |
Analytica 6.2 |
binary data term | in-memory image | GetFromBinaryData( ..., typeFlags:8 ) |
Analytica 6.4 |
base64 literal | binary data term | base64'.... |
Analytica 6.2 |
base64 text | binary data term | Evaluate( f"base64'{txt}'") | Analytica 6.2
| |
base64 literal | image | GetFromBinaryData( base64'...', typeFlags:8 ) |
Analytica 6.4 |
base64 text | image | GetFromBinaryData( f"base64'{txt}'", typeFlags:8 ) |
Analytica 6.4 |
binary data term | base64 literal text | f"{data:b}" |
Analytica 6.2 |
hexadecimal literal | binary data term | base16'.... |
Analytica 6.4 |
hexadecimal text | binary data term | Evaluate( f"base16'{txt}'") | Analytica 6.4
| |
hexadecimal literal | image | GetFromBinaryData( base16'...', typeFlags:8 ) |
Analytica 6.4 |
hexadecimal text | image | ImageFromHex( text ) |
Analytica 5.0 |
binary data term | hexadecimal literal text | f"{data:X}" |
Analytica 6.4 |
binary data term | hexadecimal text (digits only) | f"{data:H}" |
Analytica 6.4 |
Enable comment auto-refresher