// GetTarget returns a reader for the desired target or an error. // N.B. The caller is responsible for closing the reader. func (s HTTPStore) GetTarget(path string) (io.ReadCloser, error) { url, err := s.buildTargetsURL(path) if err != nil { return nil, err } logrus.Debug("Attempting to download target: ", url.String()) resp, err := utils.Download(*url) if err != nil { return nil, err } return resp.Body, nil }
// GetMeta downloads the named meta file with the given size. A short body // is acceptable because in the case of timestamp.json, the size is a cap, // not an exact length. func (s HTTPStore) GetMeta(name string, size int64) (json.RawMessage, error) { url, err := s.buildMetaURL(name) if err != nil { return nil, err } resp, err := utils.Download(*url) if err != nil { return nil, err } defer resp.Body.Close() b := io.LimitReader(resp.Body, int64(size)) body, err := ioutil.ReadAll(b) if err != nil { return nil, err } return json.RawMessage(body), nil }