Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rzane committed Nov 24, 2020
1 parent 88bd8d5 commit 6ff9e35
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,54 @@ iex> FileStore.delete(store, "bar")
:ok
```

Delete files in bulk:

```elixir
iex> FileStore.delete_all(store, "profile/images/")
:ok
```

## Middleware

#### Logger

To enable logging, just wrap your store with the logging middleware:

```elixir
FileStore.Adapters.Disk.new([...])
|> FileStore.Middleware.Logger.new(store)
|> FileStore.read("test.txt")
iex> store
...> |> FileStore.Middleware.Logger.new(store)
...> |> FileStore.read("test.txt")
# 02:37:30.724 [debug] READ OK key="test.txt"
{:ok, "hello"}
```

#### Errors

The errors middleware will wrap error values:

```elixir
iex> store
...> |> FileStore.Middleware.Errors.new()
...> |> FileStore.read("bizcorp.jpg")
{:error, %FileStore.Error{...}}
```

One of the following structs will be returned:

- `FileStore.Error`
- `FileStore.UploadError`
- `FileStore.DownloadError`

Because the error implements the `Exception` behaviour, you can `raise` it.

#### Prefix

The prefix adapter allows you to prepend a prefix to all operations.
The prefix middleware allows you to prepend a prefix to all operations.

```elixir
FileStore.Adapters.Disk.new([...])
|> FileStore.Middleware.Prefix.new(prefix: "company/logos")
|> FileStore.read(store, "bizcorp.jpg")
iex> store
...> |> FileStore.Middleware.Prefix.new(prefix: "company/logos")
...> |> FileStore.read("bizcorp.jpg")
```

In the example above, `bizcorp.jpg` was translated to `companies/logos/bizcorp.jpg`.
Expand Down

0 comments on commit 6ff9e35

Please sign in to comment.