Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: add an in-memory writer/seeker to io package #21592
I wanted to ask for your opinion regarding adding a type to the
Since there is currently no
You can check out the use case on my repo, basically, in some serverless/PaaS environments (e.g. GAE), you can't use the filesystem even if you'd like, so if a library that you are using needs a writer/seeker and expects a file for that (the only stdlib implementation), you need to implement your own in-memory writer/seeker or use a third party package like the one I mentioned above.
What version of Go are you using (
It's unclear that this is needed enough to be worth having in the standard library. What code takes a WriteSeeker as its input? The standard library defines io.WriteSeeker but defines nothing that expects or returns one (in contrast to io.ReadSeeker, which is expected by http.ServeContent and returned by a few other functions).
We left Seek out of bytes.Buffer to avoid being forced to keep old data around that had been written and then read back.
If we were going to add something I think we'd want to add something that implements both io.WriteSeeker and io.WriterAt, but still it's not clear that it's important enough to be here. We need to see more evidence of need.
If we had well-defined interfaces for a VFS (related: #14106 #5636), then it would be interesting to have a
A version I've used for testing purposes: https://godoc.org/github.com/dsnet/golib/memfile
@rsc Regarding your question about what code takes io.WriteSeeker as input - I've seen quite a few examples. This happens when someone expects a file but wants to be a bit more generic. You can view one example here: https://github.com/unidoc/unidoc/blob/3c340d1085ea5eecf0e06e8360a6e11f8828e183/pdf/creator/creator.go#L450
About the need to have something like this in the stdlib - IMHO, it could be justified if the following two conditions are satisfied:
As for (2), I think the repo I shared shows that this condition suffices.
Regarding the need, well, it's hard for me to measure such a thing, but I can guess that according to the activity/feedback on StackOverflow and on the repo I shared (8 starts in a few days since uploaded), there is at least some need.