Skip to content

Instantly share code, notes, and snippets.

@vKxni
Created June 6, 2022 09:54
Show Gist options
  • Save vKxni/189e4dc428eb02e0dc0462d7fac03e03 to your computer and use it in GitHub Desktop.
Save vKxni/189e4dc428eb02e0dc0462d7fac03e03 to your computer and use it in GitHub Desktop.
Eixir Binary
defmodule Binary do
def write(text, filename) do
binary = :erlang.term_to_binary(text)
File.write(filename, binary)
end
def read(filename) do
case File.read(filename) do
{:ok, binary} -> :erlang.binary_to_term(binary)
{:error, _reason} -> "The file does not exist."
end
end
end
# Binary.write("Hello, world!", "binaryfile")
# Binary.read("binaryfile")
# => "Hello, world!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment