Commit 45f9d32f authored by Matt Butcher's avatar Matt Butcher

Add LoadData() for server-side reading.

parent 476e71f5
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment