fix(loader): export BudgetedReader for cross-package use

Signed-off-by: Benoit Tigeot <benoit.tigeot@lifen.fr>
pull/31748/head
Benoit Tigeot 4 days ago
parent 868e210145
commit 378311fd38
No known key found for this signature in database
GPG Key ID: 8E6D4FC8AEBDA62C

@ -23,26 +23,26 @@ import (
"os"
)
// budgetedReader tracks cumulative file reads against a size limit.
type budgetedReader struct {
// BudgetedReader tracks cumulative file reads against a size limit.
type BudgetedReader struct {
max int64
remaining int64
}
// newBudgetedReader creates a new budgetedReader with the given maximum decompressed chart size.
// The remaining budget is initialized to the maximum size.
func NewBudgetedReader(max int64) *budgetedReader {
return &budgetedReader{
// NewBudgetedReader creates a BudgetedReader with the given maximum total size.
// The remaining budget is initialized to the maximum.
func NewBudgetedReader(max int64) *BudgetedReader {
return &BudgetedReader{
max: max,
remaining: max,
}
}
// readFileWithBudget reads a file and decrements remaining by the bytes read.
// It returns an error if the total would exceed the maximum decompressed chart size.
// ReadFileWithBudget reads a file and decrements the remaining budget by the bytes read.
// It returns an error if the total would exceed the configured maximum.
// The read is capped via io.LimitReader so a file that grows between stat
// and read cannot cause unbounded memory allocation.
func (r *budgetedReader) ReadFileWithBudget(path string, size int64) ([]byte, error) {
func (r *BudgetedReader) ReadFileWithBudget(path string, size int64) ([]byte, error) {
if size > r.remaining {
return nil, fmt.Errorf("chart exceeds maximum decompressed size of %d bytes", r.max)
}

Loading…
Cancel
Save