@@ -89,6 +89,10 @@ func (r CollectorResult) GetReader(bundlePath string, relativePath string) (io.R
8989 return bytes .NewReader (r [relativePath ]), nil
9090 }
9191
92+ if bundlePath == "" {
93+ return nil , errors .New ("cannot create reader, bundle path is empty" )
94+ }
95+
9296 filename := filepath .Join (bundlePath , relativePath )
9397 f , err := os .Open (filename )
9498 if err != nil {
@@ -98,9 +102,10 @@ func (r CollectorResult) GetReader(bundlePath string, relativePath string) (io.R
98102 return f , nil
99103}
100104
101- func (r CollectorResult ) GetWriter (bundlePath string , relativePath string ) (io.WriteCloser , error ) {
102- if r [relativePath ] != nil {
103- return nil , errors .New ("writing to memory is not implemented" )
105+ func (r CollectorResult ) GetWriter (bundlePath string , relativePath string ) (io.Writer , error ) {
106+ if bundlePath == "" {
107+ var b bytes.Buffer
108+ return & b , nil
104109 }
105110
106111 fileDir , _ := filepath .Split (relativePath )
@@ -120,6 +125,19 @@ func (r CollectorResult) GetWriter(bundlePath string, relativePath string) (io.W
120125 return f , nil
121126}
122127
128+ func (r CollectorResult ) CloseWriter (bundlePath string , relativePath string , writer interface {}) error {
129+ if c , ok := writer .(io.Closer ); ok {
130+ return errors .Wrap (c .Close (), "failed to close writer" )
131+ }
132+
133+ if b , ok := writer .(* bytes.Buffer ); ok {
134+ r [relativePath ] = b .Bytes ()
135+ return nil
136+ }
137+
138+ return errors .Errorf ("cannot close writer of type %T" , writer )
139+ }
140+
123141func TarSupportBundleDir (bundlePath string , input CollectorResult , outputFilename string ) error {
124142 fileWriter , err := os .Create (outputFilename )
125143 if err != nil {
0 commit comments