Created
June 6, 2022 09:54
-
-
Save vKxni/189e4dc428eb02e0dc0462d7fac03e03 to your computer and use it in GitHub Desktop.
Eixir Binary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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