| 183 | } |
| 184 | |
| 185 | func (pd *ParallelDownload) mergeFile() { |
| 186 | defer pd.wg.Done() |
| 187 | file, err := pd.getOutputFile() |
| 188 | if err != nil { |
| 189 | pd.errCh <- err |
| 190 | return |
| 191 | } |
| 192 | for i := 0; ; i++ { |
| 193 | task := pd.popTask(i) |
| 194 | tempFile, err := os.Open(task.tempFilename) |
| 195 | if err != nil { |
| 196 | pd.errCh <- err |
| 197 | return |
| 198 | } |
| 199 | _, err = io.Copy(file, tempFile) |
| 200 | tempFile.Close() |
| 201 | if err != nil { |
| 202 | pd.errCh <- err |
| 203 | return |
| 204 | } |
| 205 | if i < pd.lastIndex { |
| 206 | continue |
| 207 | } |
| 208 | break |
| 209 | } |
| 210 | if pd.client.DebugLog { |
| 211 | pd.client.log.Debugf("removing temporary directory %s", pd.tempDir) |
| 212 | } |
| 213 | err = os.RemoveAll(pd.tempDir) |
| 214 | if err != nil { |
| 215 | pd.errCh <- err |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | func (pd *ParallelDownload) Do(ctx ...context.Context) error { |
| 220 | err := pd.ensure() |