exfile v0.2.1 Exfile.Backend behaviour

Represents a backend that stores files.

Summary

Functions

A convenience function to call backend.backend_mod.delete(backend, file_id)

A convenience function to call backend.backend_mod.exists?(backend, file_id)

A convenience function to call backend.backend_mod.get(backend, file_id)

A convenience function to call backend.backend_mod.open(backend, file_id)

A convenience function to call backend.backend_mod.path(backend, file_id)

A convenience function to call backend.backend_mod.size(backend, file_id)

A convenience function to call backend.backend_mod.upload(backend, uploadable)

Callbacks

Delete a file from the backend, identified by file_id

Construct an Exfile.File struct representing the given file_id

Open a file from the backend. This function should download the file either to a temporary file or to memory in the Exfile.LocalFile struct

Get the size of a file from the backend

upload/2 must handle at least two cases of uploadable

Types

backend :: t
t :: %Exfile.Backend{backend_mod: term, backend_name: term, directory: term, hasher: term, max_size: term, meta: term}
uploadable ::
  %Exfile.File{backend: term, backend_meta: term, id: term, meta: term} |
  %Exfile.LocalFile{io: term, meta: term, path: term}

Functions

delete(backend, file_id)

Specs

delete(backend, file_id) ::
  :ok |
  {:error, :file.posix}

A convenience function to call backend.backend_mod.delete(backend, file_id)

exists?(backend, file_id)

Specs

exists?(backend, file_id) :: boolean

A convenience function to call backend.backend_mod.exists?(backend, file_id)

get(backend, file_id)

Specs

get(backend, file_id) :: %Exfile.File{backend: term, backend_meta: term, id: term, meta: term}

A convenience function to call backend.backend_mod.get(backend, file_id)

open(backend, file_id)

Specs

open(backend, file_id) ::
  {:ok, %Exfile.LocalFile{io: term, meta: term, path: term}} |
  {:error, :file.posix}

A convenience function to call backend.backend_mod.open(backend, file_id)

path(backend, file_id)

Specs

path(backend, file_id) :: Path.t

A convenience function to call backend.backend_mod.path(backend, file_id)

size(backend, file_id)

Specs

size(backend, file_id) ::
  {:ok, pos_integer} |
  {:error, :file.posix}

A convenience function to call backend.backend_mod.size(backend, file_id)

upload(backend, uploadable)

Specs

upload(backend, uploadable) ::
  {:ok, %Exfile.File{backend: term, backend_meta: term, id: term, meta: term}} |
  {:error, atom}

A convenience function to call backend.backend_mod.upload(backend, uploadable)

Callbacks

delete(backend, file_id)

Specs

delete(backend, file_id) ::
  :ok |
  {:error, :file.posix}

Delete a file from the backend, identified by file_id.

exists?(backend, file_id)

Specs

exists?(backend, file_id) :: boolean
get(backend, file_id)

Specs

get(backend, file_id) :: %Exfile.File{backend: term, backend_meta: term, id: term, meta: term}

Construct an Exfile.File struct representing the given file_id.

init(map)

Specs

init(map) :: backend | {:error, atom}
open(backend, file_id)

Specs

open(backend, file_id) ::
  {:ok, %Exfile.LocalFile{io: term, meta: term, path: term}} |
  {:error, :file.posix}

Open a file from the backend. This function should download the file either to a temporary file or to memory in the Exfile.LocalFile struct.

path(backend, file_id)

Specs

path(backend, file_id) :: Path.t
size(backend, file_id)

Specs

size(backend, file_id) ::
  {:ok, pos_integer} |
  {:error, :file.posix}

Get the size of a file from the backend

upload(backend, uploadable)

Specs

upload(backend, uploadable) ::
  {:ok, %Exfile.File{backend: term, backend_meta: term, id: term, meta: term}} |
  {:error, atom}

upload/2 must handle at least two cases of uploadable:

  1. an %Exfile.File{}
  2. an %Exfile.LocalFile{}

You may elect to implement a third case that handles uploading between identical backends, if there is a more efficient way to implement it. See Exfile.Backend.FileSystem.upload/2 for an example.