-
Notifications
You must be signed in to change notification settings - Fork 5
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
Avoid byte slice parameters #9
Comments
You are right about this being inefficient for large values, but the simple key-value interface was intentional. It allows implementing simple backends like the memory backend, redis backends and memcached backends without every backend that does not support streaming values having to implement a temporary buffer and without every access having to go through an open/read-or-write/close step. The target project would not have blobs larger that about 10 MB before inefficiencies in other places would become an issue. Even 100 MB would be workable in many use cases, even if less efficient. For use cases where it does matter, I propose optional backend interfaces as described in #2 and #3. Simpleblob would use that backend interface to provide an efficient streaming API when implemented, and fall back to buffering with a Such an approach offers the following benefits:
|
You're right, this should be optional and probably regarded as As such, would following interfaces be more suitable? // A ReaderStorage provides an optimized io.ReadCloser.
type ReaderStorage interface {
// NewReader returns an io.ReadCloser, allowing stream reading of named value from the underlying backend.
NewReader(ctx context.Context, name string) (io.ReadCloser, error)
}
// A WriterStorage provides an optimized io.WriteCloser.
type WriterStorage interface {
// NewWriter returns an io.WriteCloser, allowing stream writing to named key in the underlying backend.
NewWriter(ctx context.Context, name string) (io.WriteCloser, error)
}
// NewReader returns an optimized io.ReadCloser for backend if available, else a basic buffered implementation.
func NewReader(ctx context.Context, st Interface, name string) (io.ReadCloser, error)
// NewWriter returns an optimized io.WriteCloser for backend if available, else a basic buffered implementation.
func NewWriter(ctx context.Context, st Interface, name string) (io.WriteCloser, error) The default |
That looks quite clean and consistent, I like it!
You are right. This way most storage backends will not even need to implement |
As we're passing potentially large amounts of data, providing functions dealing in byte slices can lead to storing a large amount of data in memory without need.
Thus, the functions provided by simpleblob should deal only in
io.Reader
andio.Writer
. Turning byte slices into anio.Reader
and back should be the user's concern, provided they need to.We should take advantage of the package not being spread yet and
Interface
being explicitly about to change to do this work.The details remain to be determined, but it could be shaped as:
See also:
The text was updated successfully, but these errors were encountered: