-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Per this reddit comment:
I would suggest having an optional variant that takes some sort of cache size limit as well, in the general spirit of "I should always be able to set limits on the resources an unbounded stream will consume". It is effectively impossible to implement that from the outside (you could but you'd basically be reimplementing the entire package for that). Exceeding the cache size can then return a special error for that case.
A potential solution (using func opts) might look like:
stream := streamcache.New(os.Stdin, streamcache.MaxCacheSize(1000000))
r := stream.NewReader(ctx)
if _, err := io.Copy(dest, r); err != nil {
if errors.Is(err, streamcache.ErrCacheLimit) {
// ... do something
}
}Maybe func opts are overkill when there's only one option. It could also be something like:
stream := streamcache.NewWithLimit(os.Stdin, 100000)Or maybe just a method on Stream:
stream := streamcache.New(os.Stdin)
stream.SetMaxCacheSize(1000000)Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request