MCPcopy Index your code
hub / github.com/coder/coder / DownloadWithFormat

Method DownloadWithFormat

codersdk/files.go:48–62  ·  view source on GitHub ↗

Download fetches a file by uploaded hash, but it forces format conversion.

(ctx context.Context, id uuid.UUID, format string)

Source from the content-addressed store, hash-verified

46
47// Download fetches a file by uploaded hash, but it forces format conversion.
48func (c *Client) DownloadWithFormat(ctx context.Context, id uuid.UUID, format string) ([]byte, string, error) {
49 res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/files/%s?format=%s", id.String(), format), nil)
50 if err != nil {
51 return nil, "", err
52 }
53 defer res.Body.Close()
54 if res.StatusCode != http.StatusOK {
55 return nil, "", ReadBodyAsError(res)
56 }
57 data, err := io.ReadAll(res.Body)
58 if err != nil {
59 return nil, "", err
60 }
61 return data, res.Header.Get("Content-Type"), nil
62}

Callers 5

DownloadMethod · 0.95
TestDownloadFunction · 0.80
templatePullMethod · 0.80
WorkspaceInfoFunction · 0.80
RunFunction · 0.80

Calls 6

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
CloseMethod · 0.65
GetMethod · 0.65
StringMethod · 0.45
ReadAllMethod · 0.45

Tested by 1

TestDownloadFunction · 0.64