Skip to content

Commit

Permalink
use better config name.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrav committed Aug 1, 2023
1 parent 0194151 commit 19008c5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/sources/chunker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,33 @@ func Chunker(originalChunk *Chunk) chan *Chunk {
return chunkChan
}

type chunkerConfig struct {
type chunkReaderConfig struct {
chunkSize int
totalSize int
peekSize int
}

// ConfigOption is a function that configures a chunker.
type ConfigOption func(*chunkerConfig)
type ConfigOption func(*chunkReaderConfig)

// WithChunkSize sets the chunk size.
func WithChunkSize(size int) ConfigOption {
return func(c *chunkerConfig) {
return func(c *chunkReaderConfig) {
c.chunkSize = size
}
}

// WithTotalChunkSize sets the total chunk size.
// This is the chunk size plus the peek size.
func WithTotalChunkSize(size int) ConfigOption {
return func(c *chunkerConfig) {
return func(c *chunkReaderConfig) {
c.totalSize = size
}
}

// WithPeekSize sets the peek size.
func WithPeekSize(size int) ConfigOption {
return func(c *chunkerConfig) {
return func(c *chunkReaderConfig) {
c.peekSize = size
}
}
Expand All @@ -92,9 +92,9 @@ func NewChunkReader(opts ...ConfigOption) ChunkReader {
return createReaderFn(config)
}

func applyOptions(opts []ConfigOption) *chunkerConfig {
func applyOptions(opts []ConfigOption) *chunkReaderConfig {
// Set defaults.
config := &chunkerConfig{
config := &chunkReaderConfig{
chunkSize: ChunkSize, // default
totalSize: TotalChunkSize, // default
peekSize: PeekSize, // default
Expand All @@ -107,13 +107,13 @@ func applyOptions(opts []ConfigOption) *chunkerConfig {
return config
}

func createReaderFn(config *chunkerConfig) ChunkReader {
func createReaderFn(config *chunkReaderConfig) ChunkReader {
return func(ctx context.Context, reader io.Reader) (<-chan []byte, <-chan error) {
return readInChunks(ctx, reader, config)
}
}

func readInChunks(ctx context.Context, reader io.Reader, config *chunkerConfig) (<-chan []byte, <-chan error) {
func readInChunks(ctx context.Context, reader io.Reader, config *chunkReaderConfig) (<-chan []byte, <-chan error) {
const channelSize = 1
chunkReader := bufio.NewReaderSize(reader, config.chunkSize)
dataChan := make(chan []byte, channelSize)
Expand Down

0 comments on commit 19008c5

Please sign in to comment.