HTTP.Blob (http_fetch v0.8.0)
Represents a blob of binary data, similar to JavaScript's Blob.
A Blob contains raw data along with metadata about its MIME type and size. This module implements the Browser Fetch API Blob interface for Elixir.
Examples
# Create a blob
blob = HTTP.Blob.new(<<1, 2, 3, 4>>, "application/octet-stream")
# Access properties
HTTP.Blob.size(blob) # 4
HTTP.Blob.type(blob) # "application/octet-stream"
# Convert to binary
data = HTTP.Blob.to_binary(blob)
Summary
Functions
Creates a new Blob from binary data with a specified MIME type.
Returns the Blob's size in bytes.
Converts the Blob to a binary, extracting the raw data.
Returns the Blob's MIME type.
Types
@type t() :: %HTTP.Blob{data: binary(), size: non_neg_integer(), type: String.t()}
Functions
Creates a new Blob from binary data with a specified MIME type.
Parameters
data- Binary data to store in the blobtype- MIME type string (default: "application/octet-stream")
Examples
iex> blob = HTTP.Blob.new(<<1, 2, 3>>, "image/png")
iex> blob.type
"image/png"
iex> blob.size
3
@spec size(t()) :: non_neg_integer()
Returns the Blob's size in bytes.
Examples
iex> blob = HTTP.Blob.new(<<1, 2, 3, 4, 5>>, "application/octet-stream")
iex> HTTP.Blob.size(blob)
5
Converts the Blob to a binary, extracting the raw data.
Examples
iex> blob = HTTP.Blob.new(<<1, 2, 3>>, "application/octet-stream")
iex> HTTP.Blob.to_binary(blob)
<<1, 2, 3>>
Returns the Blob's MIME type.
Examples
iex> blob = HTTP.Blob.new(<<>>, "text/plain")
iex> HTTP.Blob.type(blob)
"text/plain"