File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace React \Stream ;
4+
5+ use React \Promise \Deferred ;
6+ use React \Promise \PromisorInterface ;
7+ use React \Stream \WritableStream ;
8+
9+ class BufferedSink extends WritableStream implements PromisorInterface
10+ {
11+ private $ buffer = '' ;
12+ private $ deferred ;
13+
14+ public function __construct ()
15+ {
16+ $ this ->deferred = new Deferred ();
17+
18+ $ this ->on ('pipe ' , array ($ this , 'handlePipeEvent ' ));
19+ $ this ->on ('error ' , array ($ this , 'handleErrorEvent ' ));
20+ }
21+
22+ public function handlePipeEvent ($ source )
23+ {
24+ Util::forwardEvents ($ source , $ this , array ('error ' ));
25+ }
26+
27+ public function handleErrorEvent ($ e )
28+ {
29+ $ this ->deferred ->reject ($ e );
30+ }
31+
32+ public function write ($ data )
33+ {
34+ $ this ->buffer .= $ data ;
35+ }
36+
37+ public function close ()
38+ {
39+ if ($ this ->closed ) {
40+ return ;
41+ }
42+
43+ parent ::close ();
44+ $ this ->deferred ->resolve ($ this ->buffer );
45+ }
46+
47+ public function promise ()
48+ {
49+ return $ this ->deferred ->promise ();
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments