Skip to content
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

Add a "cache size limit" option #5

Open
neilotoole opened this issue Mar 13, 2024 · 0 comments
Open

Add a "cache size limit" option #5

neilotoole opened this issue Mar 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@neilotoole
Copy link
Owner

neilotoole commented Mar 13, 2024

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)
@neilotoole neilotoole added the enhancement New feature or request label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant