PlanDownload decides the transfer strategy and chunk count for a download. fileSize should be obtained from a probe command; if 0 or negative the plan assumes chunked shell transfer with a single probe-then-decide chunk.
(fileSize int, userAgent string)
| 146 | // fileSize should be obtained from a probe command; if 0 or negative the plan |
| 147 | // assumes chunked shell transfer with a single probe-then-decide chunk. |
| 148 | func PlanDownload(fileSize int, userAgent string) TransferPlan { |
| 149 | profile := MatchAgentProfile(userAgent) |
| 150 | |
| 151 | plan := TransferPlan{ |
| 152 | TotalSize: fileSize, |
| 153 | AgentName: profile.Name, |
| 154 | } |
| 155 | |
| 156 | if fileSize > 0 && fileSize <= smallFileThreshold { |
| 157 | plan.Strategy = StrategyDirectTool |
| 158 | plan.NumChunks = 1 |
| 159 | return plan |
| 160 | } |
| 161 | |
| 162 | plan.Strategy = StrategyShellBase64 |
| 163 | plan.ChunkSize = profile.ChunkSizeBytes |
| 164 | |
| 165 | if fileSize <= 0 { |
| 166 | // Unknown size; caller should probe first. |
| 167 | plan.NumChunks = 0 |
| 168 | return plan |
| 169 | } |
| 170 | |
| 171 | if fileSize <= profile.ChunkSizeBytes { |
| 172 | plan.NumChunks = 1 |
| 173 | } else { |
| 174 | plan.NumChunks = int(math.Ceil(float64(fileSize) / float64(profile.ChunkSizeBytes))) |
| 175 | } |
| 176 | return plan |
| 177 | } |
| 178 | |
| 179 | // --------------------------------------------------------------------------- |
| 180 | // Chunk generation |