rzane / file_store

🗄️ A unified interface for file storage backends
MIT License
19 stars 3 forks source link

Clarify that `write/3` only accepts binary data #8

Closed rzane closed 4 years ago

rzane commented 4 years ago

In #6, @halostatue pointed out that the declaration of write/3 said that it accepted any iodata. The recommended solution was to call IO.iodata_to_binary/1 on the incoming content.

I tried to write a test for this behavior, but the test ended up looking like this:

:ok = FileStore.write(store, "foo", [?b, "a", ["r"]])
{:ok, "bar"} = FileStore.read(store, "foo")

That test passes for the disk and S3 adapters, but fails for the memory adapter, so we'd have to also convert to binary there as well.

I don't love that you put in iodata, but get out a binary. Instead, I think it is simpler to just say that write/3 and read/2 only operate on binary data. People using this library can simply call IO.iodata_to_binary/1 before calling write.

:ok = FileStore.write(store, "foo",  IO.iodata_to_binary([?b, "a", ["r"]]))
{:ok, "bar"} = FileStore.read(store, "foo")

Closes #6