68 public function seek( $offset, $whence = SEEK_SET ) {
71 $this->offset = $offset;
75 $this->offset += $offset;
79 $this->offset = strlen( $this->contents ) + $offset;
83 throw new InvalidArgumentException(
"Invalid value for \$whence" );
85 if ( $this->offset > strlen( $this->contents ) ) {
86 throw new InvalidArgumentException(
"Cannot seek beyond the end of a StringStream" );
88 if ( $this->offset < 0 ) {
89 throw new InvalidArgumentException(
"Cannot seek before the start of a StringStream" );
102 if ( $this->offset === strlen( $this->contents ) ) {
103 $this->contents .= $string;
105 $this->contents = substr_replace( $this->contents, $string,
106 $this->offset, strlen( $string ) );
108 $this->offset += strlen( $string );
109 return strlen( $string );
116 public function read( $length ) {
117 if ( $this->offset === 0 && $length >= strlen( $this->contents ) ) {
118 $ret = $this->contents;
119 } elseif ( $this->offset >= strlen( $this->contents ) ) {
122 $ret = substr( $this->contents, $this->offset, $length );
124 $this->offset += strlen( $ret );