Blob Class
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.
The old Buffer class has been renamed Blob. All functionality remains the same.
Blob Class
Members
Blob (int size = 0)
Constructor. Creates a new blob of the specified size.Arguments
- int size - Blob size.
int tell ()
Returns the current blob offset.Return value
The blob offset.void resize (int size)
Allocates the required memory and resizes the blob.Arguments
- int size - The size of the blob, in bytes.
int getSize ()
Returns the current size of the blob.Return value
The size of the blob.int compress (Stream dest, int quality)
Compresses the blob 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
Returns 1 if the data is successfully compressed; otherwise, 0.int seekEnd (int offset)
Seeks the position relative to the end of the blob.Arguments
- int offset - The offset from the end of the blob, in bytes.
Return value
Returns 1 if the blob position indicator is successfully set; otherwise, 0.String getMD5 ()
Returns the 128-bit MD5 checksum.Return value
The 128-bit MD5 checksum.int seekCur (int offset)
Seeks the position relative to the current offset.Arguments
- int offset - The offset from the current position of the indicator, in bytes.
Return value
Returns 1 if the new blob position indicator is successfully set; otherwise, 0.String getCRC32 ()
Returns the 32-bit CRC checksum.Return value
The 32-bit CRC checksum.int seekSet (int offset)
Seeks the position relative to the start of blob.Arguments
- int offset - The offset from the beginning of the blob, in bytes.
Return value
Returns 1 if the blob position indicator is successfully set; otherwise, 0.int getc ()
Returns the next symbol from the blob.Return value
The blob symbol.int decompress (Stream src)
Reads and decompresses a previously compressed blob from a given stream.Arguments
- Stream src - Stream to read data from.
Return value
Returns 1 if the blob is successfully decompressed; 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 successfully decoded; otherwise, 0.int get (int offset)
Returns the value of the specified byte in the blob.Arguments
- int offset - The offset, in bytes.
Return value
The byte value.int eof ()
Checks if the end of the blob has been reached.Return value
1 if the end of blob is reached; otherwise, 0.String getSHA1 ()
Returns the 160-bit SHA1 checksum.Return value
The 160-bit SHA1 checksum.void clear ()
Clears the size of the blob to 0.void set (int offset, int value)
Sets the value of the specified byte in the blob.Arguments
- int offset - The offset in the blob.
- int value - The byte value.
StringStack<256> encode ()
Encodes the blob into the base64 encoded string.Return value
The base64 encoded string.void reserve (int size)
Reserves the blob, i.e. allocates (size * 1.5) bytes without resizing the blob.The blob will be resized dynamically when the allocated memory is filled.
Arguments
- int size - The size of the allocated memory, in bytes.
Blob create (Stream stream)
Blob constructor.Arguments
- Stream stream - Size of the blob in bytes.
Return value
int flush ()
Flushes the blob. This function has an empty body; it is created for Blob class to have the same number of methods as the File class has.Return value
Returns 1 if the blob is successfully flushed; otherwise, 0.void allocate (int size)
Allocates the required memory without resizing the blob.The blob will be resized dynamically when the allocated memory is filled.
Arguments
- int size - Size of the allocated memory, in bytes.
Last update: 2017-07-03
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)