# Blob

A **Blob** object represents a chunk of binary data. Scripting languages like _VBScript_ and _JScript_ have no built-in support for binary data - this object can be used to allocate a chunk of memory and manipulate it in a similar way to low-level languages like C. You can use **Blob** objects in conjunction with the [**File**](file) object to read or write binary data from or to disk files.

**Blob** objects are convertible to and from two types of ActiveX arrays - a _SAFEARRAY_ of type _VT\_UI1_ (known as an **array**) and a _SAFEARRAY_ of type _VT\_VARIANT_, with each variant holding a _VT\_UI1_ (known as a **VB array**). You can initialize a **Blob** with either of these two types of array (either when creating it via the **DOpusFactory.Blob** method or with the **Blob.CopyFrom** method), and you can also convert a **Blob** back to an array with the **ToArray** and **ToVBArray** methods. Support for these array types is dependent on the scripting language.

You can read and write individual bytes within the **Blob** by indexing the byte offset starting from 0. For example, _my\_blob(5) = 128_ would set the value of the sixth byte in the blob to 128.

| Property Name | Return Type                       | Description                                                                                |
| ------------- | --------------------------------- | ------------------------------------------------------------------------------------------ |
| size          | _object:_[**FileSize**](filesize) | Returns a [**FileSize**](filesize) object representing the size of this **Blob** in bytes. |

| Method Name | **Arguments**                                                                                                                                                    | Return Type                       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Compare     | <p>&#x3C;<a href="Blob:source">Blob:source</a>><br>&#x3C;int:to><br>&#x3C;int:from><br>&#x3C;int:size></p>                                                       | _int_                             | <p>Compares the contents of this <strong>Blob</strong> against another <strong>Blob</strong> (or array). By default the entire contents of the two blobs are compared. The optional parameters that let you configure the operation are:</p><p>to - specifies the byte offset within this <strong>Blob</strong> to compare against. Defaults to 0.<br>from - specifies the byte offset within the source <strong>Blob</strong> to compare with. Defaults to 0.<br>size - specifies the number of bytes to compare. Defaults to the full size of the source <strong>Blob</strong>.</p><p>The return value is <strong>0</strong> if the two blobs are the same. A value of <strong>-1</strong> indicates this blob is less than the other blob, and <strong>1</strong> indicates this blob is greater than the other blob.</p>                                                                                                                                                                                                                                                                                                  |
| CopyFrom    | <p>&#x3C;<a href="Blob:source">Blob:source</a>><br>&#x3C;int:to><br>&#x3C;int:from><br>&#x3C;int:size></p><p><em>or</em><br><br>&#x3C;string><br>&#x3C;type></p> | _none_                            | <p>Copies data from the source <strong>Blob</strong> (or array) into this <strong>Blob</strong>. By default the entire contents of the source <strong>Blob</strong> will be copied over the top of this one. The optional parameters that let you configure the operation are:</p><p>to - specifies the byte offset within this <strong>Blob</strong> to copy to. Defaults to 0.<br>from - specifies the byte offset within the source <strong>Blob</strong> to copy from. Defaults to 0.<br>size - specifies the number of bytes to copy. Defaults to the full size of the source <strong>Blob</strong>.</p><p>As well as copying from another <strong>Blob</strong>, you can use this method to initialise a <strong>Blob</strong> from a string. By default the <strong>Blob</strong> will be set to the Unicode form of the string; if you pass <strong>"utf8"</strong> as the second parameter it will initialise the <strong>Blob</strong> with the UTF8-encoded form of the string.</p><p>If this <strong>Blob</strong> is not currently large enough to contain the copied data it will be resized automatically.</p> |
| Find        | <p>&#x3C;<a href="Blob:search">Blob:search</a>><br>&#x3C;int:from><br>&#x3C;int:size></p>                                                                        | _object:_[**FileSize**](filesize) | <p>Searches the contents of this <strong>Blob</strong> for the data contained in another <strong>Blob</strong> (or array). By default the entire contents of this <strong>Blob</strong> are searched. The optional <strong>from</strong> parameter lets you specify the starting position for the search, and the optional <strong>size</strong> parameter lets you specify the length of data in this Blob to search through.<br>The return value is -1 if the search data were not found, otherwise the offset from the start of the <strong>Blob</strong> data is returned.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| Free        | _none_                                                                                                                                                           | _none_                            | Frees the memory associated with this **Blob** and resets its size to 0.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| Init        | _none_                                                                                                                                                           | _none_                            | Initialises the contents of the **Blob** (every byte within the blob will be set to 0). Equivalent to _Set(0)_.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| Resize      | \<int:size>                                                                                                                                                      | _none_                            | Resizes the **Blob** to the specified number of bytes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Reverse     | _none_                                                                                                                                                           | _none_                            | Reverses the contents of the **Blob**.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Set         | <p>&#x3C;byte:value><br>&#x3C;int:to><br>&#x3C;int:size></p>                                                                                                     | _none_                            | Sets the contents of the **Blob** to the specified byte value (every byte within the blob will be set to that value). By default the whole **Blob** will be affected. The option _to_ parameter lets you specify a byte offset to start at, and the optional _size_ parameter lets you control the number of bytes affected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ToArray     | <p>&#x3C;int:from><br>&#x3C;int:size></p>                                                                                                                        | <p>SAFEARRAY of<br>VT_UI1</p>     | <p>Converts the contents of this <strong>Blob</strong> to a <em>SAFEARRAY</em> of type <em>VT_UI1</em>. By default the entire contents of the <strong>Blob</strong> will be copied to the array. The optional parameters that let you configure the operation are:<br>from - specifies the byte offset within the source <strong>Blob</strong> to copy from. Defaults to 0.<br>size - specifies the number of bytes to copy. Defaults to the full size of the source <strong>Blob</strong>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ToVBArray   | <p>&#x3C;int:from><br>&#x3C;int:size></p>                                                                                                                        | <p>SAFEARRAY of<br>VT_VARIANT</p> | <p>Converts the contents of this <strong>Blob</strong> to a <em>SAFEARRAY</em> of type <em>VT_VARIANT</em>. Each variant in the array contains a <em>VT_UI1</em>. By default the entire contents of the <strong>Blob</strong> will be copied to the array. The optional parameters that let you configure the operation are:</p><p>from - specifies the byte offset within the source <strong>Blob</strong> to copy from. Defaults to 0.<br>size - specifies the number of bytes to copy. Defaults to the full size of the source <strong>Blob</strong>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
