Started implementation on the new bpm file structure

This commit is contained in:
2024-10-10 12:36:29 +03:00
parent c8939614b1
commit 76efa42bcf
4 changed files with 312 additions and 194 deletions
+40
View File
@@ -0,0 +1,40 @@
package utils
import (
"archive/tar"
"errors"
"io"
"os"
)
func ReadTarballContent(tarballPath, fileToExtract string) ([]byte, error) {
file, err := os.Open(tarballPath)
if err != nil {
return nil, err
}
defer file.Close()
tr := tar.NewReader(file)
for {
header, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return nil, err
}
if header.Name == fileToExtract {
if header.Typeflag != tar.TypeReg {
return nil, errors.New("file to extract must be a regular file")
}
bytes, err := io.ReadAll(tr)
if err != nil {
return nil, err
}
return bytes, nil
}
}
return nil, errors.New("could not file in tarball")
}