# Class LittleGhost::Artifact

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Artifact.html

Represents a file, image, or document produced by a Tool or supplied to a Run.
LittleGhost sends supported media to the model once and may store the same
bytes for filesystem Tools. Inline artifacts contain their bytes. Deferred
artifacts contain an application-defined reference that the block passed to
Configuration#artifacts may use to load the bytes.

    image = LittleGhost::Artifact.new(
      data: File.binread("chart.png"),
      media_type: "image/png",
      name: "chart.png"
    )

    download = LittleGhost::Artifact.deferred(
      reference: {file_id: "file-481"},
      media_type: "application/pdf",
      name: "report.pdf"
    )

## Inheritance

`LittleGhost::Artifact < Object`

## Attributes

<a id="attribute-i-bytes"></a>
### `bytes` (R)

Known byte count, otherwise nil for an unresolved artifact.

<a id="attribute-i-data"></a>
### `data` (R)

Binary content for an inline artifact, otherwise nil.

<a id="attribute-i-media_type"></a>
### `media_type` (R)

MIME media type used to present the artifact.

<a id="attribute-i-metadata"></a>
### `metadata` (R)

Deeply frozen application metadata.

<a id="attribute-i-name"></a>
### `name` (R)

Optional display filename.

<a id="attribute-i-reference"></a>
### `reference` (R)

Application-defined deferred reference, or generated Workspace reference after
storage; otherwise nil.

## Class methods

<a id="method-c-deferred"></a>
### `.deferred`

```ruby
.deferred(reference:, media_type:, name: nil, metadata: {})
```

Creates an artifact whose bytes may be loaded later by the block passed to
Configuration#artifacts.

<a id="method-c-new"></a>
### `.new`

```ruby
.new(data:, media_type:, name: nil, metadata: {})
```

Creates an inline artifact from binary `data` and a MIME `media_type`.

## Instance methods

<a id="method-i-3D-3D"></a>
### `#==`

```ruby
#==(other)
```

Compares all immutable artifact fields.

<a id="method-i-deferred-3F"></a>
### `#deferred?`

```ruby
#deferred?()
```

Whether this artifact requires an application resolver.

<a id="method-i-eql-3F"></a>
### `#eql?`

```ruby
#eql?(other)
```

Uses the same field comparison when an artifact is a Hash key.

<a id="method-i-hash"></a>
### `#hash`

```ruby
#hash()
```

Computes a Hash key from all immutable artifact fields.

<a id="method-i-inline-3F"></a>
### `#inline?`

```ruby
#inline?()
```

Whether this artifact contains its bytes directly.

<a id="method-i-inspect"></a>
### `#inspect`

```ruby
#inspect()
```

Avoids placing bytes, names, metadata, or deferred references in diagnostics.
