forked from security/hakurei
internal/pkg: return reader for files
This improves efficiency for cache hits. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -2,7 +2,6 @@ package pkg
|
||||
|
||||
import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/bzip2"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
@@ -78,12 +77,17 @@ func (a *tarArtifact) Cure(c *CureContext) (err error) {
|
||||
var tr io.ReadCloser
|
||||
|
||||
{
|
||||
var data []byte
|
||||
data, err = c.LoadData(a.f)
|
||||
if err != nil {
|
||||
|
||||
if tr, err = c.OpenFile(a.f); err != nil {
|
||||
return
|
||||
}
|
||||
tr = io.NopCloser(bytes.NewReader(data))
|
||||
defer func(f io.ReadCloser) {
|
||||
closeErr := f.Close()
|
||||
if err == nil {
|
||||
err = closeErr
|
||||
}
|
||||
}(tr)
|
||||
tr = io.NopCloser(tr)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user