예제 #1
0
 public function testExceedingHighwaterMarkReturnsFalseButStillBuffers()
 {
     $buffer = new BufferStream(5);
     $this->assertEquals(3, $buffer->write('hi '));
     $this->assertFalse($buffer->write('hello'));
     $this->assertEquals('hi hello', (string) $buffer);
     $this->assertEquals(4, $buffer->write('test'));
 }
예제 #2
0
 /**
  * @param int $length
  *
  * @return void|null
  */
 private function pump($length)
 {
     if ($this->source) {
         do {
             $data = call_user_func($this->source, $length);
             if ($data === false || $data === null) {
                 $this->source = null;
                 return;
             }
             $this->buffer->write($data);
             $length -= strlen($data);
         } while ($length > 0);
     }
 }