GenerateDownloadChunks generates shell commands that read sequential chunks of a file via dd+base64.
(filePath string, plan TransferPlan)
| 220 | // GenerateDownloadChunks generates shell commands that read sequential chunks |
| 221 | // of a file via dd+base64. |
| 222 | func GenerateDownloadChunks(filePath string, plan TransferPlan) []DownloadChunk { |
| 223 | if plan.Strategy == StrategyDirectTool || plan.TotalSize <= 0 { |
| 224 | return nil |
| 225 | } |
| 226 | |
| 227 | chunkSize := plan.ChunkSize |
| 228 | if chunkSize <= 0 { |
| 229 | chunkSize = defaultProfile.ChunkSizeBytes |
| 230 | } |
| 231 | |
| 232 | var chunks []DownloadChunk |
| 233 | for offset := 0; offset < plan.TotalSize; offset += chunkSize { |
| 234 | size := chunkSize |
| 235 | if offset+size > plan.TotalSize { |
| 236 | size = plan.TotalSize - offset |
| 237 | } |
| 238 | |
| 239 | cmd := fmt.Sprintf("dd if='%s' bs=1 skip=%d count=%d 2>/dev/null | base64", filePath, offset, size) |
| 240 | |
| 241 | chunks = append(chunks, DownloadChunk{ |
| 242 | Index: len(chunks), |
| 243 | Offset: offset, |
| 244 | Size: size, |
| 245 | Command: cmd, |
| 246 | }) |
| 247 | } |
| 248 | return chunks |
| 249 | } |
| 250 | |
| 251 | // --------------------------------------------------------------------------- |
| 252 | // File size probe |
no outgoing calls