MCPcopy Create free account
hub / github.com/imroc/req / getOutputFile

Method getOutputFile

parallel_download.go:276–301  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

274}
275
276func (pd *ParallelDownload) getOutputFile() (io.Writer, error) {
277 outputFile := pd.output
278 if outputFile != nil {
279 return outputFile, nil
280 }
281 if pd.filename == "" {
282 u, err := urlpkg.Parse(pd.url)
283 if err != nil {
284 panic(err)
285 }
286 paths := strings.Split(u.Path, "/")
287 for i := len(paths) - 1; i > 0; i-- {
288 if paths[i] != "" {
289 pd.filename = paths[i]
290 break
291 }
292 }
293 if pd.filename == "" {
294 pd.filename = "download"
295 }
296 }
297 if pd.client.outputDirectory != "" && !filepath.IsAbs(pd.filename) {
298 pd.filename = filepath.Join(pd.client.outputDirectory, pd.filename)
299 }
300 return os.OpenFile(pd.filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, pd.perm)
301}

Callers 1

mergeFileMethod · 0.95

Calls 1

ParseMethod · 0.80

Tested by

no test coverage detected