Add LoadData() for server-side reading.

pull/271/head
Matt Butcher 9 years ago
parent 476e71f5d3
commit 45f9d32ffc

@ -18,6 +18,7 @@ package chart
import (
"archive/tar"
"bytes"
"compress/gzip"
"errors"
"fmt"
@ -240,6 +241,29 @@ func LoadDir(chart string) (*Chart, error) {
}, nil
}
// LoadData loads a chart from data, where data is a []byte containing a gzipped tar file.
func LoadData(data []byte) (*Chart, error) {
b := bytes.NewBuffer(data)
unzipped, err := gzip.NewReader(b)
if err != nil {
return nil, err
}
defer unzipped.Close()
untarred := tar.NewReader(unzipped)
c, err := loadTar(untarred)
if err != nil {
return nil, err
}
cf, err := LoadChartfile(filepath.Join(c.tmpDir, ChartfileName))
if err != nil {
return nil, err
}
c.chartyaml = cf
return &Chart{loader: c}, nil
}
// Load loads a chart from a chart archive.
//
// A chart archive is a gzipped tar archive that follows the Chart format

@ -17,6 +17,7 @@ limitations under the License.
package chart
import (
"io/ioutil"
"path/filepath"
"testing"
@ -57,7 +58,6 @@ func TestLoadDir(t *testing.T) {
}
func TestLoad(t *testing.T) {
c, err := Load(testarchive)
if err != nil {
t.Errorf("Failed to load chart: %s", err)
@ -75,6 +75,27 @@ func TestLoad(t *testing.T) {
}
}
func TestLoadData(t *testing.T) {
data, err := ioutil.ReadFile(testarchive)
if err != nil {
t.Errorf("Failed to read testarchive file: %s", err)
return
}
c, err := LoadData(data)
if err != nil {
t.Errorf("Failed to load chart: %s", err)
return
}
if c.Chartfile() == nil {
t.Error("No chartfile was loaded.")
return
}
if c.Chartfile().Name != "frobnitz" {
t.Errorf("Expected name to be frobnitz, got %q", c.Chartfile().Name)
}
}
func TestLoadIll(t *testing.T) {
c, err := Load(testill)
if err != nil {

Loading…
Cancel
Save