69 public function seek( $offset, $whence = SEEK_SET ) {
72 $this->offset = $offset;
76 $this->offset += $offset;
80 $this->offset = strlen( $this->contents ) + $offset;
84 throw new InvalidArgumentException(
"Invalid value for \$whence" );
86 if ( $this->offset > strlen( $this->contents ) ) {
87 throw new InvalidArgumentException(
"Cannot seek beyond the end of a StringStream" );
89 if ( $this->offset < 0 ) {
90 throw new InvalidArgumentException(
"Cannot seek before the start of a StringStream" );
103 if ( $this->offset === strlen( $this->contents ) ) {
104 $this->contents .= $string;
106 $this->contents = substr_replace( $this->contents, $string,
107 $this->offset, strlen( $string ) );
109 $this->offset += strlen( $string );
110 return strlen( $string );
117 public function read( $length ) {
118 if ( $this->offset === 0 && $length >= strlen( $this->contents ) ) {
119 $ret = $this->contents;
120 } elseif ( $this->offset >= strlen( $this->contents ) ) {
123 $ret = substr( $this->contents, $this->offset, $length );
125 $this->offset += strlen( $ret );