-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: io: add ZeroReader io.Reader #57317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you leave it as zeroing only this could make use of #56351, but you could also make it a bit more flexible by making it something like |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This proposal has been added to the active column of the proposals project |
There is a question of what type to give this thing. It is both a Reader and a ReaderAt, and we don't have an interface for that type. We would probably need to do:
There is also potential confusion with it being a reader that has no (zero) bytes in length, not a reader that has an infinite number of zero bytes. "A reader that returns 0 bytes" can be read either way. There is also the question of whether this arises enough to be worthwhile. The uses in the standard library are pretty fringe. I might also worry about uses in crypto and then having to preserve some properties of the implementation that we might or might not remember to preserve. Are the use cases really here? |
Note that the new |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Needing to read a stream of zero-bytes is an ocassional use-case of an
io.Reader
.io.ZeroReader
would be the/dev/zero
counterpoint to/dev/null
andio.Discard
.One particular use-case is with
cipher.StreamReader
to create a CSPRNG (this is the crypto/ecdsa use below).I've proposed it be called
io.ZeroReader
, but it could also be calledio.Zero
or similar.Proposed API:
There are two uses of this I can find in the standard library:
go/src/archive/tar/reader.go
Lines 811 to 818 in 3a7a528
go/src/crypto/ecdsa/ecdsa.go
Lines 446 to 456 in 34ab0bc
...and five more in test code: here and here.
Admittedly the archive/tar use could be written differently (it seems to be just zeroing a slice), but the crypto/ecdsa use does require it.
There are also two examples in the standard library of
io.ReaderAt
zeroing:go/src/internal/xcoff/file.go
Lines 449 to 458 in ea14d1b
go/src/debug/pe/file.go
Lines 185 to 194 in ea14d1b
The text was updated successfully, but these errors were encountered: