decodeBase64FileContent decodes base64-encoded file content returned by the GitHub API. The GitHub API wraps lines at 60 characters and may include surrounding whitespace, so both are stripped before decoding.
(raw string)
| 195 | // The GitHub API wraps lines at 60 characters and may include surrounding whitespace, |
| 196 | // so both are stripped before decoding. |
| 197 | func decodeBase64FileContent(raw string) ([]byte, error) { |
| 198 | cleaned := strings.ReplaceAll(strings.TrimSpace(raw), "\n", "") |
| 199 | content, err := base64.StdEncoding.DecodeString(cleaned) |
| 200 | if err != nil { |
| 201 | downloadLog.Printf("Base64 decode failed: cleaned_len=%d, err=%v", len(cleaned), err) |
| 202 | return nil, fmt.Errorf("failed to decode file content: %w", err) |
| 203 | } |
| 204 | downloadLog.Printf("Decoded base64 file content: bytes=%d", len(content)) |
| 205 | return content, nil |
| 206 | } |