> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Erase files

> Erase a stored file with its fact, or let the host retire files no fact keeps.

`ctx.erase(file)` erases a file: its own unit closes, its bytes go, and its
fact's history stays readable for the table's `history`. It returns the
erasure's `sys.erasures` point. Delete or patch the fact that kept the file
in the same transaction. `ctx.retire` takes only a member.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { sys } from "@bijectionhq/bijection";

const fact = await ctx.get(receipts(id));
if (fact !== null) {
  await ctx.erase(fact.file);
  await ctx.delete(receipts(id));
}
```

You can also just delete the fact. A stored file that no committed fact
keeps is retired by the host, so a library that drops a fact needs no
second write.

Erasing closes the file's own unit, so it is admitted as any erasure is:
only in the live world (not inside a branch), from a function whose label
is at or below the file's, by a caller whose role lists the file's label in
`erase` (each of its labels; a public file names none), by a site that may
write the file's table when the file names one, and judged by `act.erase`
guards on the file's unit. A role that clears a label without erasing it
refuses `GrantRequired`. Grant both rights to let a finance clerk erase files:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { label, role } from "@bijectionhq/bijection";

export const finance = label();
export const clerk = role({ clear: [finance], erase: [finance] });
```

To destroy a file's facts in every version, with evidence, erase their
unit; see [data lifetime](https://docs.bijection.com/database/history-and-lifetime.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.