-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopened.go
36 lines (29 loc) · 769 Bytes
/
opened.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package resources
import (
"io"
"github.com/juju/errors"
)
// Opened provides both the resource info and content.
type Opened struct {
Resource
io.ReadCloser
}
// Content returns the "content" for the opened resource.
func (o Opened) Content() Content {
return Content{
Data: o.ReadCloser,
Size: o.Size,
Fingerprint: o.Fingerprint,
}
}
func (o Opened) Close() error {
return errors.Trace(o.ReadCloser.Close())
}
// Opener exposes the functionality for opening a resource.
type Opener interface {
// OpenResource returns an opened resource with a reader that will
// stream the resource content.
OpenResource(name string) (Opened, error)
}