Skip to content

Commit

Permalink
Cache UnicodeData.txt to priv
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Thatcher committed Jul 12, 2011
1 parent c27435a commit c162fb1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
A pure Erlang IDNA implementation.

An attempt will be made to read from priv/UnicodeData.txt. If the file does not exist,
it is downloaded from unicode.org, and an attempt is made to save it to the above filename,
though no checking is done as to whether or not this succeeded.

Quick start:

$ make
Expand Down
Empty file added priv/.placeholder
Empty file.
9 changes: 8 additions & 1 deletion src/idna.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@

start() ->
idna_unicode_data:start(),
idna_unicode_data:load("http://www.unicode.org/Public/UNIDATA/UnicodeData.txt").
File = code:priv_dir('erlang') ++ "/UnicodeData.txt",
case file:read_file(File) of
{'ok', Data} -> idna_unicode_data:load(Data);
{'error', _} ->
{ok, {{_, 200, _}, _, GetData}} = http:request(get, {"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt", []}, [], [{body_format, binary}]),
file:write_file(File, GetData),
idna_unicode_data:load(GetData)
end.

to_ascii(Domain) ->
to_ascii(string:tokens(idna_unicode:downcase(Domain), "."), []).
Expand Down

0 comments on commit c162fb1

Please sign in to comment.