func()

in pkg/client/artifacts.go [26:52]


func (c *artifactsClient) Fetch(ctx context.Context, id string, sha256 string) ([]byte, error) {
	var data bytes.Buffer
	client, err := c.client.artifactClient.Fetch(ctx, &proto.ArtifactFetchRequest{
		Token:  c.client.token,
		Id:     id,
		Sha256: sha256,
	})
	if err != nil {
		return nil, err
	}
	for {
		msg, err := client.Recv()
		if err != nil {
			return nil, err
		}
		switch res := msg.ContentEof.(type) {
		case *proto.ArtifactFetchResponse_Content:
			if _, err := data.Write(res.Content); err != nil {
				return nil, err
			}
		case *proto.ArtifactFetchResponse_Eof:
			return data.Bytes(), nil
		default:
			return nil, errors.New("unknown ArtifactContentEof type")
		}
	}
}