handle download and its options
(ctx context.Context, pid string, nodes []string, options map[string]string)
| 36 | |
| 37 | // handle download and its options |
| 38 | func streamDownload(ctx context.Context, pid string, nodes []string, options map[string]string) { |
| 39 | // get defaults |
| 40 | filename := pid |
| 41 | var filterFunc filter.FilterFunc = nil |
| 42 | var compressionFormat string = "" |
| 43 | var archiveFormat string = "" |
| 44 | |
| 45 | // use options if exist |
| 46 | if fn, has := options["filename"]; has { |
| 47 | filename = fn |
| 48 | } |
| 49 | if fl, has := options["filter"]; has { |
| 50 | if filter.Has(fl) { |
| 51 | filterFunc = filter.Filter(fl) |
| 52 | } |
| 53 | } |
| 54 | if cp, has := options["compression"]; has { |
| 55 | compressionFormat = cp |
| 56 | } |
| 57 | if ar, has := options["archive"]; has { |
| 58 | archiveFormat = ar |
| 59 | } |
| 60 | var files []*file.FileInfo |
| 61 | |
| 62 | // process nodes |
| 63 | for _, nid := range nodes { |
| 64 | // get node |
| 65 | n, err := node.Load(nid) |
| 66 | if (err != nil) || !n.HasFile() || n.HasFileLock() { |
| 67 | continue |
| 68 | } |
| 69 | // get filereader |
| 70 | nf, err := n.FileReader() |
| 71 | if err != nil { |
| 72 | nf.Close() |
| 73 | continue |
| 74 | } |
| 75 | // add to file array |
| 76 | var fileInfo file.FileInfo |
| 77 | if n.Type == "subset" { |
| 78 | if n.File.Size == 0 { |
| 79 | // handle empty subset file |
| 80 | fileInfo.R = append(fileInfo.R, nf) |
| 81 | } else { |
| 82 | idx := index.New() |
| 83 | fullRange := "1-" + strconv.FormatInt(n.Subset.Index.TotalUnits, 10) |
| 84 | recSlice, err := idx.Range(fullRange, n.Path()+"/"+n.Id+".subset.idx", n.Subset.Index.TotalUnits) |
| 85 | if err != nil { |
| 86 | nf.Close() |
| 87 | continue |
| 88 | } |
| 89 | for _, rec := range recSlice { |
| 90 | fileInfo.R = append(fileInfo.R, io.NewSectionReader(nf, rec[0], rec[1])) |
| 91 | } |
| 92 | } |
| 93 | } else { |
| 94 | fileInfo.R = append(fileInfo.R, nf) |
| 95 | } |
no test coverage detected