github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/resources/opened.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package resources 5 6 import ( 7 "io" 8 9 "github.com/juju/errors" 10 ) 11 12 // Opened provides both the resource info and content. 13 type Opened struct { 14 Resource 15 io.ReadCloser 16 } 17 18 // Content returns the "content" for the opened resource. 19 func (o Opened) Content() Content { 20 return Content{ 21 Data: o.ReadCloser, 22 Size: o.Size, 23 Fingerprint: o.Fingerprint, 24 } 25 } 26 27 func (o Opened) Close() error { 28 return errors.Trace(o.ReadCloser.Close()) 29 } 30 31 // Opener exposes the functionality for opening a resource. 32 type Opener interface { 33 // OpenResource returns an opened resource with a reader that will 34 // stream the resource content. 35 OpenResource(name string) (Opened, error) 36 }