Skip to content
This repository
Newer
Older
100644 39 lines (28 sloc) 0.971 kb
a39fab8b »
2004-09-13 added example docs on how to stream data
1
2 <erl>
3
78112471 »
2011-10-31 whitespace cleanup
4 out(A) ->
a39fab8b »
2004-09-13 added example docs on how to stream data
5 Self = self(),
6 spawn(fun() ->
0be3c7e8 »
2008-02-14 untabified all of yaws
7 %% Create a random number
8 {_A1, A2, A3} = now(),
9 random:seed(erlang:phash(node(), 100000),
10 erlang:phash(A2, A3),
11 A3),
12 Sz = random:uniform(100000),
13
14 %% Read random junk
78112471 »
2011-10-31 whitespace cleanup
15 S="dd if=/dev/urandom count=1 bs=" ++
0be3c7e8 »
2008-02-14 untabified all of yaws
16 integer_to_list(Sz) ++ " 2>/dev/null",
17 P = open_port({spawn, S}, [binary,stream, eof]),
18
19 rec_loop(Self, P)
20 end),
78112471 »
2011-10-31 whitespace cleanup
21
a39fab8b »
2004-09-13 added example docs on how to stream data
22 {streamcontent, "application/octet-stream", <<>>}.
23
78112471 »
2011-10-31 whitespace cleanup
24
a39fab8b »
2004-09-13 added example docs on how to stream data
25 rec_loop(YawsPid, P) ->
26 receive
0be3c7e8 »
2008-02-14 untabified all of yaws
27 {P, {data, BinData}} ->
28 yaws_api:stream_chunk_deliver(YawsPid, BinData),
29 rec_loop(YawsPid, P);
30 {P, eof} ->
31 port_close(P),
32 yaws_api:stream_chunk_end(YawsPid),
33 exit(normal)
a39fab8b »
2004-09-13 added example docs on how to stream data
34 end.
35
36
37 </erl>
38
Something went wrong with that request. Please try again.