// download fetches the icon for the given ID and applies an optional
// transformation on the data before writing it to a local file.
download fetches the icon for the given ID and applies an optional
transformation on the data before writing it to a local file.
// download fetches the icon for the given ID and applies an optional // transformation on the data before writing it to a local file .
func download(ID string, pipeline ImagePipeline) error {
	resp, err := http.Get(fmt.Sprintf(URLTemplate, ID))
	if err != nil {
		return err
	}
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("unexpected status: %s", resp.Status)
	}
	defer resp.Body.Close()
	out, err := os.Create(fmt.Sprintf(FileTemplate, ID))
	if err != nil {
		return err
	}
	defer out.Close()
	if pipeline == nil {
		_, err = io.Copy(out, resp.Body) 
	} else {
		err = pipeline(resp.Body, out)
	}
	return err
}
func download ( ID string , pipeline ImagePipeline ) error { resp , err := http . Get ( fmt . Sprintf ( URLTemplate , ID ) ) if err != nil { return err } if resp . StatusCode != http . StatusOK { return fmt . Errorf ( " " , resp . Status ) } defer resp . Body . Close ( ) out , err := os . Create ( fmt . Sprintf ( FileTemplate , ID ) ) if err != nil { return err } defer out . Close ( ) if pipeline == nil { _ , err = io . Copy ( out , resp . Body ) } else { err = pipeline ( resp . Body , out ) } return err }
download fetches the icon for the given ID and applies an optional
transformation on the data before writing it to a local file.
download fetches the icon for the given ID and applies an optional transformation on the data before writing it to a local file .
// TODO: should probably verify bytes written