Difference between revisions of "In-memory binary data terms"

 
(4 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
== Binary data terms (or "blobs") ==
 
== Binary data terms (or "blobs") ==
  
Sometimes you may need to hold some arbitrary raw, opaque data in memory. The data cannot be directly interpreted (at least not easily), and might contain any sequence of bytes. Such an in-memory block is sometimes called a "blob". The more formal name is a ''binary data term''.
+
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 therefore just a block of memory with arbitrary data. Often it is just 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.
+
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 ==
 
== Creating a binary data term in memory ==
Line 22: Line 23:
 
* <code>[[BinaryDataSize]](data)</code> -- returns the number of bytes
 
* <code>[[BinaryDataSize]](data)</code> -- returns the number of bytes
 
* <code>[[GetFromBinaryData]](...)</code>
 
* <code>[[GetFromBinaryData]](...)</code>
 +
* <code>[[ParseProtoBuf]]</code> -- 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.
 
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.
Line 30: Line 32:
  
 
{| border="1"
 
{| border="1"
!! From !! To !! Method !! Required release
+
! From !! To !! Method !! Required release
 
|-
 
|-
| Binary file (or part of) || binary data term || [[ReadBinaryFile]] || [[Analytica 6.2]]
+
| binary file (or part of) || binary data term || [[ReadBinaryFile]] || [[Analytica 6.2]]
 
|-
 
|-
 
| binary data term (or part of) || Binary file || [[WriteBinaryFile]] || [[Analytica 6.2]]
 
| binary data term (or part of) || Binary file || [[WriteBinaryFile]] || [[Analytica 6.2]]
 
|-
 
|-
| Part of binary data term || another binary data term || <code>[[GetFromBinaryData]](...typeFlags:7)</code> || [[Analytica 6.2]]
+
| part of binary data term || another binary data term || <code>[[GetFromBinaryData]](...typeFlags:7)</code> || [[Analytica 6.2]]
 
|-
 
|-
| Image file || binary data term || <code>[[ReadBinaryFile]](filename,typeFlags:7)</code> || [[Analytica 6.4]]
+
| image file || binary data term || <code>[[ReadBinaryFile]](filename,typeFlags:7)</code> || [[Analytica 6.4]]
 
|-
 
|-
| In-memory image || binary data term || <code>[[WriteImageFile]]("<>", image)</code> || [[Analytica 6.4]]
+
| in-memory image || binary data term || <code>[[WriteImageFile]]("<>", image)</code> || [[Analytica 6.4]]
 
|-
 
|-
| binary data term | image file || <code>[[WriteBinaryFile]](...,typeflags:7) </code><br/>''The binary data must contain the bytes for a valid image.'' || [[Analytica 6.2]]
+
| binary data term || image file || <code>[[WriteBinaryFile]](...,typeflags:7) </code><br/>''The binary data must contain the bytes for a valid image.'' || [[Analytica 6.2]]
 
|-
 
|-
 
| binary data term || in-memory image || <code>[[GetFromBinaryData]]( ..., typeFlags:8 )</code> || [[Analytica 6.4]]
 
| binary data term || in-memory image || <code>[[GetFromBinaryData]]( ..., typeFlags:8 )</code> || [[Analytica 6.4]]

Latest revision as of 22:24, 10 February 2024



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.

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

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

See Also

Comments


You are not allowed to post comments.