Jido.VFS.Adapter.Local (Jido.VFS v1.0.0)

View Source

Jido.VFS adapter for the local filesystem.

Direct usage

iex> prefix = System.tmp_dir!()
iex> filesystem = Jido.VFS.Adapter.Local.configure(prefix: prefix)
iex> :ok = Jido.VFS.write(filesystem, "test.txt", "Hello World")
iex> {:ok, "Hello World"} = Jido.VFS.read(filesystem, "test.txt")

Usage with a module

defmodule LocalFileSystem do
  use Jido.VFS.Filesystem,
    adapter: Jido.VFS.Adapter.Local,
    prefix: prefix
end

LocalFileSystem.write("test.txt", "Hello World")
{:ok, "Hello World"} = LocalFileSystem.read("test.txt")

Usage with Streams

The following options are available for streams:

  • :chunk_size - When reading, the amount to read, by :line (default) or by a given number of bytes.

  • :modes - A list of modes to use when opening the file for reading. For more information, see the docs for File.stream!/3.

Examples

{:ok, %File.Stream{}} = Jido.VFS.read_stream(filesystem, "test.txt")

# with custom read chunk size
{:ok, %File.Stream{line_or_bytes: 1_024, ...}} = Jido.VFS.read_stream(filesystem, "test.txt", chunk_size: 1_024)

# with custom file read modes
{:ok, %File.Stream{mode: [{:encoding, :utf8}, :binary], ...}} = Jido.VFS.read_stream(filesystem, "test.txt", modes: [encoding: :utf8])