func openArchive(entity interface{}) (r ReadSeekCloser, hash string, size int64, err error) {
	var path string
	switch entity := entity.(type) {
	case archiverTo:
		// For example: charm.CharmDir or charm.BundleDir.
		file, err := newRemoveOnCloseTempFile("entity-archive")
		if err != nil {
			return nil, "", 0, errgo.Notef(err, "cannot make temporary file")
		}
		if err := entity.ArchiveTo(file); err != nil {
			file.Close()
			return nil, "", 0, errgo.Notef(err, "cannot create entity archive")
		}
		if _, err := file.Seek(0, 0); err != nil {
			file.Close()
			return nil, "", 0, errgo.Notef(err, "cannot seek")
		}
		hash, size, err = readerHashAndSize(file)
		if err != nil {
			file.Close()
			return nil, "", 0, errgo.Mask(err)
		}
		return file, hash, size, nil
	case *charm.BundleArchive:
		path = entity.Path
	case *charm.CharmArchive:
		path = entity.Path
	default:
		return nil, "", 0, errgo.Newf("cannot get the archive for entity type %T", entity)
	}
	file, err := os.Open(path)
	if err != nil {
		return nil, "", 0, errgo.Mask(err)
	}
	hash, size, err = readerHashAndSize(file)
	if err != nil {
		file.Close()
		return nil, "", 0, errgo.Mask(err)
	}
	return file, hash, size, nil
}
// openArchive is used to turn the current charm or bundle implementations
// into readers for their corresponding archive.
// It returns the corresponding archive reader, its hex-encoded SHA384 hash
// and size.
openArchive is used to turn the current charm or bundle implementations
into readers for their corresponding archive.
It returns the corresponding archive reader, its hex-encoded SHA384 hash
and size.
// openArchive is used to turn the current charm or bundle implementations // into readers for their corresponding archive . // It returns the corresponding archive reader its hex - encoded SHA384 hash // and size .
func openArchive(entity interface{}) (r ReadSeekCloser, hash string, size int64, err error) {
	var path string
	switch entity := entity.(type) {
	case archiverTo:
		file, err := newRemoveOnCloseTempFile("entity-archive")
		if err != nil {
			return nil, "", 0, errgo.Notef(err, "cannot make temporary file")
		}
		if err := entity.ArchiveTo(file); err != nil {
			file.Close()
			return nil, "", 0, errgo.Notef(err, "cannot create entity archive")
		}
		if _, err := file.Seek(0, 0); err != nil {
			file.Close()
			return nil, "", 0, errgo.Notef(err, "cannot seek")
		}
		hash, size, err = readerHashAndSize(file)
		if err != nil {
			file.Close()
			return nil, "", 0, errgo.Mask(err)
		}
		return file, hash, size, nil
	case *charm.BundleArchive:
		path = entity.Path
	case *charm.CharmArchive:
		path = entity.Path
	default:
		return nil, "", 0, errgo.Newf("cannot get the archive for entity type %T", entity)
	}
	file, err := os.Open(path)
	if err != nil {
		return nil, "", 0, errgo.Mask(err)
	}
	hash, size, err = readerHashAndSize(file)
	if err != nil {
		file.Close()
		return nil, "", 0, errgo.Mask(err)
	}
	return file, hash, size, nil
}
func openArchive ( entity interface { } ) ( r ReadSeekCloser , hash string , size int64 , err error ) { var path string switch entity := entity . ( type ) { case archiverTo : file , err := newRemoveOnCloseTempFile ( " " ) if err != nil { return nil , " " , 0 , errgo . Notef ( err , " " ) } if err := entity . ArchiveTo ( file ) ; err != nil { file . Close ( ) return nil , " " , 0 , errgo . Notef ( err , " " ) } if _ , err := file . Seek ( 0 , 0 ) ; err != nil { file . Close ( ) return nil , " " , 0 , errgo . Notef ( err , " " ) } hash , size , err = readerHashAndSize ( file ) if err != nil { file . Close ( ) return nil , " " , 0 , errgo . Mask ( err ) } return file , hash , size , nil case * charm . BundleArchive : path = entity . Path case * charm . CharmArchive : path = entity . Path default : return nil , " " , 0 , errgo . Newf ( " " , entity ) } file , err := os . Open ( path ) if err != nil { return nil , " " , 0 , errgo . Mask ( err ) } hash , size , err = readerHashAndSize ( file ) if err != nil { file . Close ( ) return nil , " " , 0 , errgo . Mask ( err ) } return file , hash , size , nil }
openArchive is used to turn the current charm or bundle implementations
into readers for their corresponding archive.
openArchive is used to turn the current charm or bundle implementations into readers for their corresponding archive .
// For example: charm.CharmDir or charm.BundleDir.