// Acquire fetches the requested resource.
Acquire fetches the requested resource.
// Acquire fetches the requested resource .
func (cfd *CloudflaredMethod) Acquire(uri *url.URL, requrl, filename string) error {
	req, err := cfd.BuildRequest(cfd.client, uri)
	if err != nil {
		cfd.mwriter.StartURI(requrl, "", 0, false)
		return err
	}
	resp, err := cfd.client.Do(req)
	if err != nil {
		cfd.mwriter.StartURI(requrl, "", 0, false)
		return err
	}
	if resp.StatusCode != 200 {
		cfd.mwriter.StartURI(requrl, "", 0, false)
		return fmt.Errorf("GET for %s failed with %s", uri.String(), resp.Status)
	}
	cfd.mwriter.StartURI(requrl, "", resp.ContentLength, false)
	defer resp.Body.Close()
	buffer := make([]byte, 1024*16)
	hashMD5 := md5.New()   
	hashSHA1 := sha1.New() 
	hashSHA256 := sha256.New()
	hashSHA512 := sha512.New()
	fp, err := os.Create(filename)
	if err != nil {
		return fmt.Errorf("error opening file '%s': %v", filename, err)
	}
	mw := io.MultiWriter(hashMD5, hashSHA1, hashSHA256, hashSHA512, fp)
	if _, err := io.CopyBuffer(mw, resp.Body, buffer); err != nil {
		return fmt.Errorf("error reading response body: %v", err)
	}
	strMD5 := fmt.Sprintf("%x", hashMD5.Sum(nil))
	strSHA1 := fmt.Sprintf("%x", hashSHA1.Sum(nil))
	strSHA256 := fmt.Sprintf("%x", hashSHA256.Sum(nil))
	strSHA512 := fmt.Sprintf("%x", hashSHA512.Sum(nil))
	cfd.mwriter.FinishURI(requrl, filename, "", "", false, false,
		Field{"MD5-Hash", strMD5},
		Field{"MD5Sum-Hash", strMD5},
		Field{"SHA1-Hash", strSHA1},
		Field{"SHA256-Hash", strSHA256},
		Field{"SHA512-Hash", strSHA512},
	)
	return nil
}
func ( cfd * CloudflaredMethod ) Acquire ( uri * url . URL , requrl , filename string ) error { req , err := cfd . BuildRequest ( cfd . client , uri ) if err != nil { cfd . mwriter . StartURI ( requrl , " " , 0 , false ) return err } resp , err := cfd . client . Do ( req ) if err != nil { cfd . mwriter . StartURI ( requrl , " " , 0 , false ) return err } if resp . StatusCode != 200 { cfd . mwriter . StartURI ( requrl , " " , 0 , false ) return fmt . Errorf ( " " , uri . String ( ) , resp . Status ) } cfd . mwriter . StartURI ( requrl , " " , resp . ContentLength , false ) defer resp . Body . Close ( ) buffer := make ( [ ] byte , 1024 * 16 ) hashMD5 := md5 . New ( ) hashSHA1 := sha1 . New ( ) hashSHA256 := sha256 . New ( ) hashSHA512 := sha512 . New ( ) fp , err := os . Create ( filename ) if err != nil { return fmt . Errorf ( " " , filename , err ) } mw := io . MultiWriter ( hashMD5 , hashSHA1 , hashSHA256 , hashSHA512 , fp ) if _ , err := io . CopyBuffer ( mw , resp . Body , buffer ) ; err != nil { return fmt . Errorf ( " " , err ) } strMD5 := fmt . Sprintf ( " " , hashMD5 . Sum ( nil ) ) strSHA1 := fmt . Sprintf ( " " , hashSHA1 . Sum ( nil ) ) strSHA256 := fmt . Sprintf ( " " , hashSHA256 . Sum ( nil ) ) strSHA512 := fmt . Sprintf ( " " , hashSHA512 . Sum ( nil ) ) cfd . mwriter . FinishURI ( requrl , filename , " " , " " , false , false , Field { " " , strMD5 } , Field { " " , strMD5 } , Field { " " , strSHA1 } , Field { " " , strSHA256 } , Field { " " , strSHA512 } , ) return nil }
Acquire fetches the requested resource.
Acquire fetches the requested resource .
// Build our request // Handle non-200 responses // TODO: Handle other 200 codes // Close the body at the end of the method // We buffer up to 16kb at a time // We want to compute our different hashes, otherwise Apt will reject the package // #nosec // #nosec // And finally, we need to write to this file