Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 39 lines (28 sloc) 0.971 kb
a39fab8 @klacke added example docs on how to stream data
authored
1
2 <erl>
3
7811247 @vinoski whitespace cleanup
vinoski authored
4 out(A) ->
a39fab8 @klacke added example docs on how to stream data
authored
5 Self = self(),
6 spawn(fun() ->
0be3c7e @klacke untabified all of yaws
authored
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
7811247 @vinoski whitespace cleanup
vinoski authored
15 S="dd if=/dev/urandom count=1 bs=" ++
0be3c7e @klacke untabified all of yaws
authored
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),
7811247 @vinoski whitespace cleanup
vinoski authored
21
a39fab8 @klacke added example docs on how to stream data
authored
22 {streamcontent, "application/octet-stream", <<>>}.
23
7811247 @vinoski whitespace cleanup
vinoski authored
24
a39fab8 @klacke added example docs on how to stream data
authored
25 rec_loop(YawsPid, P) ->
26 receive
0be3c7e @klacke untabified all of yaws
authored
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)
a39fab8 @klacke added example docs on how to stream data
authored
34 end.
35
36
37 </erl>
38
Something went wrong with that request. Please try again.