1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
11
ziputil "github.com/juju/utils/zip"
14
type BundleArchive struct {
22
// ReadBundleArchive reads a bundle archive from the given file path.
23
func ReadBundleArchive(path string) (*BundleArchive, error) {
24
a, err := readBundleArchive(newZipOpenerFromPath(path))
32
// ReadBundleArchiveBytes reads a bundle archive from the given byte
34
func ReadBundleArchiveBytes(data []byte) (*BundleArchive, error) {
35
zopener := newZipOpenerFromReader(bytes.NewReader(data), int64(len(data)))
36
return readBundleArchive(zopener)
39
// ReadBundleArchiveFromReader returns a BundleArchive that uses
40
// r to read the bundle. The given size must hold the number
41
// of available bytes in the file.
43
// Note that the caller is responsible for closing r - methods on
44
// the returned BundleArchive may fail after that.
45
func ReadBundleArchiveFromReader(r io.ReaderAt, size int64) (*BundleArchive, error) {
46
return readBundleArchive(newZipOpenerFromReader(r, size))
49
func readBundleArchive(zopen zipOpener) (*BundleArchive, error) {
53
zipr, err := zopen.openZip()
58
reader, err := zipOpenFile(zipr, "bundle.yaml")
62
a.data, err = ReadBundleData(reader)
67
reader, err = zipOpenFile(zipr, "README.md")
71
readMe, err := ioutil.ReadAll(reader)
75
a.readMe = string(readMe)
79
// Data implements Bundle.Data.
80
func (a *BundleArchive) Data() *BundleData {
84
// ReadMe implements Bundle.ReadMe.
85
func (a *BundleArchive) ReadMe() string {
89
// ExpandTo expands the bundle archive into dir, creating it if necessary.
90
// If any errors occur during the expansion procedure, the process will
92
func (a *BundleArchive) ExpandTo(dir string) error {
93
zipr, err := a.zopen.openZip()
98
return ziputil.ExtractAll(zipr.Reader, dir)