// SaveFile reads body and then saves the file defined in body
SaveFile reads body and then saves the file defined in body
// SaveFile reads body and then saves the file defined in body
func (r *Response) SaveFile(filePath string) error {
	data, err := r.readBody()
	if err != nil {
		logger.Errorf("Can not save response to file %s Error: %v", filePath, err)
		return err
	}
	if len(data) == 0 {
		err := errors.New("Downloaded file is empty. Can not save empty response to file " + filePath)
		return err
	}
	f, err := os.Create(filePath)
	if err != nil {
		logger.Errorf("Can not create file %s Error: %v", filePath, err)
		return err
	}
	defer f.Close()
	_, err = io.Copy(f, bytes.NewReader(data))
	if err != nil {
		logger.Errorf("Can write to file %s Error: %v", filePath, err)
		return err
	}
	err = f.Sync()
	if err != nil {
		logger.Errorf("Can't sync file %s Error: %v", filePath, err)
		return err
	}
	return err
}
func ( r * Response ) SaveFile ( filePath string ) error { data , err := r . readBody ( ) if err != nil { logger . Errorf ( " " , filePath , err ) return err } if len ( data ) == 0 { err := errors . New ( " " + filePath ) return err } f , err := os . Create ( filePath ) if err != nil { logger . Errorf ( " " , filePath , err ) return err } defer f . Close ( ) _ , err = io . Copy ( f , bytes . NewReader ( data ) ) if err != nil { logger . Errorf ( " " , filePath , err ) return err } err = f . Sync ( ) if err != nil { logger . Errorf ( " " , filePath , err ) return err } return err }
SaveFile reads body and then saves the file defined in body
SaveFile reads body and then saves the file defined in body