# `Dala.Storage.Blob`
[🔗](https://github.com/manhvu/dala/blob/main/lib/dala/storage/blob.ex#L1)

Binary data handling via blob references.

Blobs are stored in native memory and referenced by an opaque handle.

## Examples

    # Create a blob from binary data
    blob_ref = Dala.Storage.Blob.create(<<1, 2, 3>>, "application/octet-stream")

    # Slice a blob
    sliced = Dala.Blob.slice(blob_ref, 0, 2)

    # Convert to base64
    base64 = Dala.Blob.to_base64(blob_ref)

    # Save to file
    {:ok, path} = Dala.Blob.to_file(blob_ref, "/tmp/blob.bin")

# `create`

```elixir
@spec create(binary(), String.t()) :: term()
```

Create a blob from binary data.

`type` is the MIME type (default: `"application/octet-stream"`).
Returns an opaque blob reference.

# `slice`

```elixir
@spec slice(term(), non_neg_integer(), non_neg_integer()) :: term()
```

Slice a blob from `start_pos` to `end_pos`.
Returns a new blob reference.

# `to_base64`

```elixir
@spec to_base64(term()) :: String.t() | nil
```

Convert a blob to a base64-encoded string. Returns `nil` if the blob is invalid.

# `to_file`

```elixir
@spec to_file(term(), String.t()) :: {:ok, String.t()} | {:error, atom()}
```

Save blob contents to a file at the given path.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
