76 public function seek( $offset, $whence = SEEK_SET ) {
79 $this->offset = $offset;
83 $this->offset += $offset;
87 $this->offset = strlen( $this->contents ) + $offset;
91 throw new InvalidArgumentException(
"Invalid value for \$whence" );
93 if ( $this->offset > strlen( $this->contents ) ) {
94 throw new InvalidArgumentException(
"Cannot seek beyond the end of a StringStream" );
96 if ( $this->offset < 0 ) {
97 throw new InvalidArgumentException(
"Cannot seek before the start of a StringStream" );
113 if ( $this->offset === strlen( $this->contents ) ) {
114 $this->contents .= $string;
116 $this->contents = substr_replace( $this->contents, $string,
117 $this->offset, strlen( $string ) );
119 $this->offset += strlen( $string );
120 return strlen( $string );
129 public function read( $length ) {
130 if ( $this->offset === 0 && $length >= strlen( $this->contents ) ) {
131 $ret = $this->contents;
132 } elseif ( $this->offset >= strlen( $this->contents ) ) {
135 $ret = substr( $this->contents, $this->offset, $length );
137 $this->offset += strlen( $ret );