# `HfHub.Commit.Operation`
[🔗](https://github.com/North-Shore-AI/hf_hub_ex/blob/v0.3.1/lib/hf_hub/commit/operation.ex#L1)

Commit operation types for file manipulation.

Operations represent changes to be made in a single commit:
- `Add` - Upload or update a file
- `Delete` - Remove a file or folder
- `Copy` - Copy an existing LFS file (efficient, no re-upload)

## Examples

    # Add a file from disk
    add_op = HfHub.Commit.Operation.add("model.bin", "/path/to/model.bin")

    # Add from binary content
    add_op = HfHub.Commit.Operation.add("config.json", ~s({"hidden_size": 768}))

    # Delete a file
    del_op = HfHub.Commit.Operation.delete("old_model.bin")

    # Delete a folder
    del_op = HfHub.Commit.Operation.delete("old_weights/", is_folder: true)

    # Copy an LFS file
    copy_op = HfHub.Commit.Operation.copy("v1/model.bin", "v2/model.bin")

# `add`

```elixir
@type add() :: %HfHub.Commit.Operation.Add{
  content: term(),
  is_committed: term(),
  is_uploaded: term(),
  path_in_repo: term(),
  upload_info: term(),
  upload_mode: term()
}
```

# `copy`

```elixir
@type copy() :: %HfHub.Commit.Operation.Copy{
  dst_path: term(),
  src_path: term(),
  src_revision: term()
}
```

# `delete`

```elixir
@type delete() :: %HfHub.Commit.Operation.Delete{
  is_folder: term(),
  path_in_repo: term()
}
```

# `t`

```elixir
@type t() :: add() | delete() | copy()
```

# `add`

```elixir
@spec add(String.t(), binary() | Path.t(), keyword()) ::
  HfHub.Commit.Operation.Add.t()
```

Creates an add operation from a file path or binary content.

Automatically computes UploadInfo (SHA256, size, sample) for the content.

## Options

- `:upload_info` - Pre-computed upload info (skips computation)

## Examples

    # From file path
    op = Operation.add("model.safetensors", "/path/to/model.safetensors")

    # From binary
    op = Operation.add("config.json", Jason.encode!(%{hidden_size: 768}))

# `base64_content`

```elixir
@spec base64_content(HfHub.Commit.Operation.Add.t()) ::
  {:ok, String.t()} | {:error, term()}
```

Gets base64-encoded content (for regular uploads).

# `copy`

```elixir
@spec copy(String.t(), String.t(), keyword()) :: HfHub.Commit.Operation.Copy.t()
```

Creates a copy operation for an existing LFS file.

Copy operations are efficient because they don't re-upload the file content.
The file must already exist in the repository (or at src_revision).

## Options

- `:src_revision` - Source revision (default: current HEAD)

## Examples

    Operation.copy("v1/model.bin", "v2/model.bin")
    Operation.copy("model.bin", "archive/model.bin", src_revision: "v1.0")

# `delete`

```elixir
@spec delete(
  String.t(),
  keyword()
) :: HfHub.Commit.Operation.Delete.t()
```

Creates a delete operation.

## Options

- `:is_folder` - Set to true to delete a folder and contents

## Examples

    Operation.delete("old_model.bin")
    Operation.delete("old_weights/", is_folder: true)

# `file_path?`

```elixir
@spec file_path?(HfHub.Commit.Operation.Add.t()) :: boolean()
```

Checks if content is from a file path vs binary data.

# `get_content`

```elixir
@spec get_content(HfHub.Commit.Operation.Add.t()) ::
  {:ok, binary()} | {:error, term()}
```

Gets the content as binary (reads file if path).

---

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