stream = $stream; $this->hash = $hash; $this->callback = $onComplete; } public function read($length): string { $data = $this->stream->read($length); $this->hash->update($data); if ($this->eof()) { $result = $this->hash->complete(); if ($this->callback) { call_user_func($this->callback, $result); } } return $data; } public function seek($offset, $whence = SEEK_SET): void { // Seeking arbitrarily is not supported. if ($offset !== 0) { return; } $this->hash->reset(); $this->stream->seek($offset); } }