Last active
April 25, 2017 19:48
-
-
Save ChrisCates/2125c2eb182d5f744750ea6ad87c9f42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func threadedRead(index int, columns string, files chan string, done chan int) { | |
| newFile, err := os.Create("./.safariql/cache_" + strconv.Itoa(index) + ".safariql") | |
| if err != nil { | |
| panic(err) | |
| } | |
| newFile.WriteString(columns + "\n") | |
| for file := range files { | |
| fileRead, err := os.Open(file) | |
| fmt.Println("Thread #", index, "reading", file) | |
| if err != nil { | |
| panic(err) | |
| } | |
| reader := csv.NewReader(fileRead) | |
| reader.Comma = ',' | |
| if err != nil { | |
| panic(err) | |
| } | |
| records := make([][]string, 10000) | |
| i := 0 | |
| for { | |
| record, err := reader.Read() | |
| if err == io.EOF { | |
| break | |
| } else if err != nil { | |
| panic(err) | |
| } | |
| records[i] = record | |
| i++ | |
| } | |
| fileRead.Close() | |
| for i := 0; i < len(records); i++ { | |
| for ii := 0; ii < len(records[i]); ii++ { | |
| newFile.WriteString(strings.TrimSpace(records[i][ii]) + "\n") | |
| } | |
| } | |
| newFile.Close() | |
| done <- index | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment