Skip to content

Simple file operations for Gleam that work on all targets (Erlang/Node/Deno)

Notifications You must be signed in to change notification settings

slegrand45/simplifile

 
 

Repository files navigation

simplifile

Package Version Hex Docs

Simplifile provides synchronous operations for working with files and directories that work for all non-browser targets (Erlang, Node, Deno, and Bun).

When should I use simplifile?

Simplifile makes a simple tradeoff: it confines itself to a subset of purely synchronous file/directory utilities so that it can have one API for all targets. Erlang and JavaScript have fundamentally different concurrency models, so bindings to async code will simply be different for different targets.

You should use simplifile if

  1. The same code running on JS and Erlang targets is important
  2. Sync file operations will not be a major performance bottleneck (dev tooling, configuration, scripting, etc.)
  3. You just wanna do some basic file operations and get on with life

If you think you need a different solutions, these projects may be helpful: File streams (erlang target)

Example

let filepath = "./test/hello.txt"
let assert Ok(_) = "Hello, World" |> write(to: filepath)
let assert Ok(_) = "Goodbye, Mars" |> append(to: filepath)
let assert Ok("Hello, WorldGoodbye, Mars") = read(from: filepath)
let assert Ok(_) = delete(filepath)
let assert Error(_) = read(from: filepath)

Installation

If available on Hex this package can be added to your Gleam project:

gleam add simplifile

and its documentation can be found at https://hexdocs.pm/simplifile.

About

Simple file operations for Gleam that work on all targets (Erlang/Node/Deno)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Gleam 74.8%
  • Erlang 12.5%
  • JavaScript 12.2%
  • Shell 0.5%