Skip to content

Commit

Permalink
Using data instead of references.
Browse files Browse the repository at this point in the history
Signed-off-by: thatInfrastructureGuy <[email protected]>
  • Loading branch information
thatInfrastructureGuy committed Jan 19, 2021
1 parent f77fba6 commit 8ae193a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (c *Converter) setCSVHeaders(csvWriter *csv.Writer) ([]string, error) {
return headers, nil
}

func (c *Converter) rowToCSV(toCSV chan []string, toGzip chan *csvBuf, wg *sync.WaitGroup) {
func (c *Converter) rowToCSV(toCSV chan []string, toGzip chan csvBuf, wg *sync.WaitGroup) {
defer wg.Done()
csvWriter, csvBuffer := c.getCSVWriter()
// Set headers
Expand All @@ -81,7 +81,7 @@ func (c *Converter) rowToCSV(toCSV chan []string, toGzip chan *csvBuf, wg *sync.

// Convert from csv to gzip
if csvBuffer.Len() >= (c.GzipBatchPerGoroutine * c.GzipGoroutines) {
toGzip <- &csvBuf{
toGzip <- csvBuf{
data: csvBuffer.Bytes(),
lastPart: false,
}
Expand All @@ -92,7 +92,7 @@ func (c *Converter) rowToCSV(toCSV chan []string, toGzip chan *csvBuf, wg *sync.
}

// Flush remaining buffer contents to gzip
toGzip <- &csvBuf{
toGzip <- csvBuf{
data: csvBuffer.Bytes(),
lastPart: true,
}
Expand Down
16 changes: 8 additions & 8 deletions gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (c *Converter) getGzipWriter(writer io.Writer) (*pgzip.Writer, error) {
return zw, err
}

func (c *Converter) csvToGzip(toGzip chan *csvBuf, w io.Writer, wg *sync.WaitGroup) {
func (c *Converter) csvToGzip(toGzip chan csvBuf, w io.Writer, wg *sync.WaitGroup) {
defer wg.Done()
var gzipBuffer *bytes.Buffer
if c.S3Upload {
Expand All @@ -46,16 +46,16 @@ func (c *Converter) csvToGzip(toGzip chan *csvBuf, w io.Writer, wg *sync.WaitGro
return
}

err = zw.Flush()
if err != nil {
c.quit <- fmt.Errorf("Error flushing contents to gzip writer: ", err)
return
}

if csvBuf.lastPart {
err = zw.Close()
if err != nil {
c.quit <- fmt.Errorf("Error flushing contents to gzip writer: ", err)
return
}
} else {
err = zw.Flush()
if err != nil {
c.quit <- fmt.Errorf("Error flushing contents to gzip writer: ", err)
c.quit <- fmt.Errorf("Error closing gzip writer: ", err)
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion sqltocsvgzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *Converter) Write(w io.Writer) (err error) {

toPreprocess := make(chan []interface{})
toCSV := make(chan []string)
toGzip := make(chan *csvBuf)
toGzip := make(chan csvBuf)

// Create 3 goroutines
wg := &sync.WaitGroup{}
Expand Down

0 comments on commit 8ae193a

Please sign in to comment.