[erlang-questions] working with files from a database
Ulf Wiger
ulf.wiger@REDACTED
Tue Jun 15 13:35:22 CEST 2010
Michael Connors wrote:
> Hi,
>
> In Erlang, is there an equivalent to the Python library StringIO? I would
> like to store files in a database as byte arrays and then retrieve them and
> serve them as files again later.
file:read_file(Filename) -> {ok, Binary}
You can plop that binary into a mnesia table if you want.
Depending on the file sizes, YMMV, of course, but for small
files, no problem.
As one of my more obscure* hacks in the 'rdbms' contrib, I used
the 'external_copies' hack in mnesia (pretty much the stuff that
http://code.google.com/p/mnesiaex/ uses for TokyoCabinet backend)
to mount a file system directory as an ordered set mnesia table.
http://jungerl.cvs.sourceforge.net/viewvc/jungerl/jungerl/lib/rdbms/src/rdbms_rofs.erl?revision=1.1&view=markup
The idea was that you define a record with attributes reusing names
from the #file_info{} record, or the attribute 'data', which would
translate to the contents of the file. The key was the filename
relative to the "mount point". After this, read access and selects
would work as on any mnesia table, but writes were not allowed
at all.
* Note that this is not supported by anyone, not even me, and
doesn't run on anything newer than OTP R12B. I just thought I'd
mention it.
BR,
Ulf W
--
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
---------------------------------------------------
---------------------------------------------------
WE'VE CHANGED NAMES!
Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.
www.erlang-solutions.com
More information about the erlang-questions
mailing list