# Reader.peekDelimiterInclusive: Fix handling of \`stream\` implementations that return 0 · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/328ae41468f3514251ac1b0726c41eca9fbc3fb5)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 328ae41468f3514251ac1b0726c41eca9fbc3fb5

Requested commit: 328ae41468f3514251ac1b0726c41eca9fbc3fb5

Commit: 328ae41468f3514251ac1b0726c41eca9fbc3fb5

Tree: 32315d9cc319b31a88afb68b0d5b7448b64cbf2d

Author: Ryan Liptak

Committer: Andrew Kelley

## Message

```
Reader.peekDelimiterInclusive: Fix handling of `stream` implementations that return 0

Previously, the logic in peekDelimiterInclusive (when the delimiter was not found in the existing buffer) used the `n` returned from `r.vtable.stream` as the length of the slice to check, but it's valid for `vtable.stream` implementations to return 0 if they wrote to the buffer instead of `w`. In that scenario, the `indexOfScalarPos` would be given a 0-length slice so it would never be able to find the delimiter.

This commit changes the logic to assume that `r.vtable.stream` can both:
- return 0, and
- modify seek/end (i.e. it's also valid for a `vtable.stream` implementation to rebase)

Also introduces `std.testing.ReaderIndirect` which helps in being able to test against Reader implementations that return 0 from `stream`/`readVec`

Fixes #25428

```

## Parents

- [60be67d3c0ba6ae15fa7115596734ab1e74fbcd3](https://git.cafe/gitcafe/zig/commit/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/328ae41468f3514251ac1b0726c41eca9fbc3fb5?format=markdown)
