diff --git a/tar/asm/getter.go b/tar/asm/getter.go index 1ea7b3d..bb5e0d1 100644 --- a/tar/asm/getter.go +++ b/tar/asm/getter.go @@ -65,6 +65,11 @@ type readCloserWrapper struct { func (w *readCloserWrapper) Close() error { return nil } // NewBufferFileGetPutter is simple in memory FileGetPutter +// +// Implication is this is memory intensive... +// Probably best for testing or light weight cases. func NewBufferFileGetPutter() FileGetPutter { - return &bufferFileGetPutter{} + return &bufferFileGetPutter{ + files: map[string][]byte{}, + } } diff --git a/tar/asm/getter_test.go b/tar/asm/getter_test.go new file mode 100644 index 0000000..4206189 --- /dev/null +++ b/tar/asm/getter_test.go @@ -0,0 +1,33 @@ +package asm + +import ( + "bytes" + "io/ioutil" + "testing" +) + +func TestGetter(t *testing.T) { + fgp := NewBufferFileGetPutter() + files := map[string][]byte{ + "file1.txt": []byte("foo"), + "file2.txt": []byte("bar"), + } + for n, b := range files { + if err := fgp.Put(n, bytes.NewBuffer(b)); err != nil { + t.Error(err) + } + } + for n, b := range files { + r, err := fgp.Get(n) + if err != nil { + t.Error(err) + } + buf, err := ioutil.ReadAll(r) + if err != nil { + t.Error(err) + } + if string(b) != string(buf) { + t.Errorf("expected %q, got %q", string(b), string(buf)) + } + } +}