[erlang-questions] Singleton question or design question for transfer file test program

Kenneth Lakin kennethlakin@REDACTED
Mon Dec 21 21:17:38 CET 2015


On 12/21/2015 11:21 AM, Bill Durksen wrote:
> I looked at the ets system for storing data in tables and tried a few
> experiments, but wasn't able to successfully store an IoDevice type in
> an ets table.

Did you see this note in the documentation for file:open/2 ?

"IoDevice is really the pid of the process which handles the file. This
process is linked to the process which originally opened the file. If
any process to which the IoDevice is linked terminates, the file will be
closed and the process itself will be terminated. An IoDevice returned
from this call can be used as an argument to the IO functions (see io(3))."

This works just fine:

1> Tab=ets:new(tab, []).
20496
2> {ok, F}=file:open("file.mp3", [read]).
{ok,<0.39.0>}
3> ets:insert(Tab, {file, F}).
true
4> ets:lookup_element(Tab, file, 1).
file
5> ets:lookup_element(Tab, file, 2).
<0.39.0>
6> file:read(ets:lookup_element(Tab, file, 2), 10).
{ok,[73,68,51,3,0,0,0,0,0,86]}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20151221/81fd9683/attachment.bin>


More information about the erlang-questions mailing list