This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine.Blob Class

Inherits from: Stream

This class is used to store data in the memory (unlike File which is stored on the disk). The blob uses either an Unigine allocator (if #define USE_MEMORY is set, by default) or a system allocator.

Example#

The code below illustrates the following process:

  • Packing data to a blob and saving compressed data to a file
  • Reading and uncompressing data from the file to the destination blob
  • Reading data from the destination blob
Source code (C#)
// creating a source blob to store data
Blob blob1 = new Blob();

// creating a file to save our blob's data to
File file = new File("test.dat", "w+");

// clearing a blob
blob1.clear();

// writing data to a blob (prefix, vector and postfix)
blob1.writeChar('B');
blob1.writeVec3(new vec3(0.1f, 0.2f, 0.3f));
blob1.writeChar('E');

// compressing blob's data with low compression and saving it to the file
blob1.compress(file.getStream(), 0);

// closing the file
file.close();

// clearing a blob
blob1.clear();

// opening the data file for reading
file.open("test.dat", "r");

// creating a second blob
Blob blob2 = new Blob();

// reading and decompressing data from the file
blob2.decompress(file.getStream());

// closing the file
file.close();

// setting current position to the beginning of the blob
blob2.seekSet(0);

// reading data from a blob (prefix, vector and postfix)
char pref = blob2.readChar(); 
vec3 v = blob2.readVec3();
char postf = blob2.readChar();

// reporting the decoded blob data and SHA1 checksum
Log.Message("\nDESTINATION: [{0}] vec({1}, {2}, {3}) [{4}] - SHA1 checksum ({5})", pref, v.x, v.y, v.z, postf, blob2.getSHA1());

// clearing a blob
blob2.clear();

Blob Class

Members


Blob ( uint size = 0 ) #

Constructor. Creates a new blob of the specified size.

Arguments

  • uint size - Blob size.

void Set ( uint offset, byte value ) #

Sets the value of the specified byte in the blob.

Arguments

  • uint offset - The offset in the blob.
  • byte value - The byte value.

byte get ( uint offset ) #

Returns the value of the specified byte in the blob.

Arguments

  • uint offset - The offset, in bytes.

Return value

The byte value.

int Getc ( ) #

Gets a next symbol from the blob.

Return value

Character read from the blob.

string GetCRC32 ( ) #

Returns the 32-bit CRC checksum.

Return value

The 32-bit CRC checksum.

void SetData ( byte[] data, uint size ) #

Sets new data to the Blob instance.
Notice
You should manage the previously stored data manually.

Arguments

  • byte[] data - Data to set to the Blob instance.
  • uint size - The size of the blob.

byte[] GetData ( ) #

Returns the current blob data.

Return value

Blob data.

string GetMD5 ( ) #

Returns a 128-bit MD5 checksum.

Return value

128-bit MD5 checksum.

string GetSHA1 ( ) #

Returns a 160-bit SHA1 checksum.

Return value

160-bit SHA1 checksum.

string GetSHA256 ( ) #

Returns a 256-bit SHA256 checksum.

Return value

256-bit SHA256 checksum.

uint GetSize ( ) #

Returns the current blob size.

Return value

Blob size.

void Allocate ( uint size ) #

Allocates the required memory without resizing the blob.
Notice
The blob will be resized dynamically when the allocated memory is filled.

Arguments

  • uint size - Size of the allocated memory, in bytes.

void Clear ( ) #

Clears the blob size to 0.

int Compress ( Stream dest, int quality ) #

Compresses the blob and writes it into the given stream.
Notice
This method uses zlib compression which is better than Lz4 (see the compressLz4() method), but significantly slower.

Arguments

  • Stream dest - Destination stream.
  • int quality - Compression quality (0 is for a fast compression, 1 is for a small size).

Return value

1 if the data is compressed successfully; otherwise, 0.

int CompressLz4 ( Stream dest, int quality ) #

Compresses the blob with Lz4 algorithm and writes it into the given stream.

Arguments

  • Stream dest - Destination stream.
  • int quality - Compression quality (0 is for a fast compression, 1 is for a small size).

Return value

1 if the data is successfully compressed; otherwise, 0.

int Decode ( string src ) #

Decodes a base64 encoded string into the blob.

Arguments

  • string src - Source base64 encoded string.

Return value

Returns 1 if the data is decoded successfully; otherwise, 0.

int DecodeZBase32 ( string src ) #

Decodes a Zbase32 encoded string into the blob.

Arguments

  • string src - Source Zbase32 encoded string.

Return value

Returns 1 if the data is decoded successfully; otherwise, 0.

int Decompress ( Stream src ) #

Reads the compressed blob from a stream and decompresses it.

Arguments

  • Stream src - Stream to read data from.

Return value

1 if the blob is decompressed successfully; otherwise, 0.

int DecompressLz4 ( Stream src ) #

Reads and decompresses a previously compressed blob with Lz4 algorithm from a given stream.

Arguments

  • Stream src - Source stream to read data from.

Return value

1 if the blob is successfully decompressed; otherwise, 0.

string Encode ( ) #

Encodes the blob into the base64 encoded string.

Return value

Base64 encoded string.

string EncodeZBase32 ( ) #

Encodes the blob into the ZBase32 encoded string.

Return value

ZBase32 encoded string.

int Eof ( ) #

Tests if the end of the blob has been reached.

Return value

Returns 1 if the end of the blob is reached; otherwise, 0.

int Flush ( ) #

Flushes the blob.

Return value

Returns 1 if the blob is flushed successfully; otherwise, 0.

void Reserve ( uint size ) #

Reserves the blob, i.e. allocates (size * 1.5) bytes without resizing the blob. It will be resized dynamically when the allocated memory is filled.

Arguments

  • uint size - The size of the allocated memory, in bytes.

void Resize ( uint size ) #

Allocates the required memory and resizes the blob.

Arguments

  • uint size - The size of the blob, in bytes.

int SeekCur ( uint offset ) #

Seeks to position relative to the current offset.

Arguments

  • uint offset - The offset from the current position of the indicator, in bytes.

Return value

Returns 1 if the blob position indicator is set successfully; otherwise, 0.

int SeekEnd ( uint offset ) #

Seeks to position relative to the end of the blob.

Arguments

  • uint offset - The offset from the end of the blob, in bytes.

Return value

Returns 1 if the blob position indicator is set successfully; otherwise, 0.

int SeekSet ( uint offset ) #

Seeks to position relative to the start of the blob.

Arguments

  • uint offset - The offset from the beginning of the blob, in bytes.

Return value

Returns 1 if the blob position indicator is set successfully; otherwise, 0.

uint Tell ( ) #

Gets the current blob offset position indicator.

Return value

Returns the current blob offset.
Last update: 2021-04-29
Build: ()