MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / ExtractMetaFromTarball

Function ExtractMetaFromTarball

go/model/model.go:295–307  ·  view source on GitHub ↗

ExtractMetaFromTarball extract metadata from given tarball and return the metadata json string. This function do not unzip the whole model tarball

(tarballName, cwd string)

Source from the content-addressed store, hash-verified

293// and return the metadata json string. This function do not
294// unzip the whole model tarball
295func ExtractMetaFromTarball(tarballName, cwd string) (*Model, error) {
296 if !strings.HasSuffix(tarballName, ".tar.gz") {
297 return nil, fmt.Errorf("given file should be a .tar.gz file")
298 }
299 cmd := exec.Command("tar", "xpf", tarballName, "-C", cwd, "./"+modelMetaFileName)
300 out, err := cmd.CombinedOutput()
301 if err != nil {
302 return nil, fmt.Errorf("can't unzip model tarball %s: %s, %v", tarballName, out, err)
303 }
304 metaPath := path.Join(cwd, modelMetaFileName)
305 defer os.Remove(metaPath)
306 return loadMeta(metaPath)
307}
308
309func loadMeta(metaFileName string) (*Model, error) {
310 data, err := ioutil.ReadFile(metaFileName)

Callers 3

ReleaseModelMethod · 0.92
releaseModelFromLocalFunction · 0.92
loadModelFromDBFunction · 0.85

Calls 2

loadMetaFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected