[erlang-questions] matching binary against a file

Mike McNally m5@REDACTED
Thu Jun 21 22:22:55 CEST 2007


> Now this is all fine as long as I first read the entire string into 
> memory, but because you can't know beforehand how many bytes will be 
> read you have to overestimate and then handle whatever is left over.

I've had success with a pattern that involves one process that reads the
file block by block and only handles (in your case) the UTF-8
interpretation. That process can send each value (character code) it
recognizes to a client process.  The higher-level code then gets a
stream of ready-to-use characters just by calling "receive".

(Actually you probably would send a tuple, like {ok, value} or the atom
eof.  That way you could send a {err, whatever} tuple if the file is
corrupted.)

--
[ I love pre-moistened towelettes ] Mike McNally -- m5@REDACTED



More information about the erlang-questions mailing list