ReadContent reads an artifact's new content from the file at path, following a symlink, or from stdin when path is "-". It also returns the directory the content's references to attached files resolve against, which is empty for stdin, as cmdutil.ReadMarkdownBodyFile gives it. Artifact content must
(path string, stdin io.ReadCloser)
| 22 | // doesn't name path, so a caller can say which artifact failed in its own |
| 23 | // words. |
| 24 | func ReadContent(path string, stdin io.ReadCloser) (content, dir string, err error) { |
| 25 | what := "file" |
| 26 | if path == "-" { |
| 27 | what = "input" |
| 28 | } |
| 29 | |
| 30 | content, dir, err = cmdutil.ReadMarkdownBodyFile(path, stdin) |
| 31 | if err != nil { |
| 32 | if pathErr, ok := errors.AsType[*fs.PathError](err); ok && pathErr.Path == path { |
| 33 | return "", "", pathErr.Err |
| 34 | } |
| 35 | return "", "", err |
| 36 | } |
| 37 | |
| 38 | if strings.TrimSpace(content) == "" { |
| 39 | return "", "", fmt.Errorf("%s is empty", what) |
| 40 | } |
| 41 | if gistShared.IsBinaryContents([]byte(content)) { |
| 42 | return "", "", fmt.Errorf("binary %s not supported", what) |
| 43 | } |
| 44 | return content, dir, nil |
| 45 | } |
| 46 | |
| 47 | // IsShortcutFile reports whether path is an Internet Shortcut file, which |
| 48 | // artifact commands read as a link. Like Windows, it goes by the .url |