forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob_manager.go
39 lines (32 loc) · 1 KB
/
blob_manager.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
37
38
39
package blobstore
import (
bosherr "github.com/cloudfoundry/bosh-agent/errors"
boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
boshsys "github.com/cloudfoundry/bosh-agent/system"
"path/filepath"
)
type BlobManager struct {
fs boshsys.FileSystem
dirProvider boshdir.Provider
}
func NewBlobManager(fs boshsys.FileSystem, dirProvider boshdir.Provider) (manager BlobManager) {
manager.fs = fs
manager.dirProvider = dirProvider
return
}
func (manager BlobManager) Fetch(blobID string) (blobBytes []byte, err error) {
blobPath := filepath.Join(manager.dirProvider.MicroStore(), blobID)
blobBytes, err = manager.fs.ReadFile(blobPath)
if err != nil {
err = bosherr.WrapError(err, "Reading blob")
}
return
}
func (manager BlobManager) Write(blobID string, blobBytes []byte) (err error) {
blobPath := filepath.Join(manager.dirProvider.MicroStore(), blobID)
err = manager.fs.WriteFile(blobPath, blobBytes)
if err != nil {
err = bosherr.WrapError(err, "Updating blob")
}
return
}