Skip to content

Commit

Permalink
64kb -> 1mb.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Aug 1, 2024
1 parent 5be770f commit e4a6c1c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/s3lib/s3lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (s *S3Client) ListFiles(fp string) ([]S3File, error) {
// It's not a typical JSON file in that it is compressed and it's new line delimited via separated via an array
// Which means we can stream this file row by row to not OOM.
func (s *S3Client) StreamJsonGzipFile(file S3File, ch chan<- dynamodb.ItemResponse) error {
const maxBufferSize = 1024 * 1024 // 1 MB or adjust as needed

defer close(ch)
result, err := s.client.GetObject(&s3.GetObjectInput{
Bucket: file.Bucket,
Expand All @@ -88,6 +90,9 @@ func (s *S3Client) StreamJsonGzipFile(file S3File, ch chan<- dynamodb.ItemRespon
defer gz.Close()

scanner := bufio.NewScanner(gz)
buf := make([]byte, maxBufferSize)
scanner.Buffer(buf, maxBufferSize)

for scanner.Scan() {
line := scanner.Bytes()
var content dynamodb.ItemResponse
Expand Down

0 comments on commit e4a6c1c

Please sign in to comment.