ReadHashWrapper.php 622 B

1234567891011121314151617181920212223
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019 Roeland Jago Douma <roeland@famdouma.nl>
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Icewind\Streams;
  7. /**
  8. * Wrapper that calculates the hash on the stream on read
  9. *
  10. * The stream and hash should be passed in when wrapping the stream.
  11. * On close the callback will be called with the calculated checksum.
  12. *
  13. * For supported hashes see: http://php.net/manual/en/function.hash-algos.php
  14. */
  15. class ReadHashWrapper extends HashWrapper {
  16. public function stream_read($count) {
  17. $data = parent::stream_read($count);
  18. $this->updateHash($data);
  19. return $data;
  20. }
  21. }