CopyExportToHost copies exported files from the container to a host directory. It returns the paths to RDF/JSON files and schema files on the host.
(containerPath string)
| 1525 | // CopyExportToHost copies exported files from the container to a host directory. |
| 1526 | // It returns the paths to RDF/JSON files and schema files on the host. |
| 1527 | func (c *LocalCluster) ReadFileFromContainer(containerPath string) ([]byte, error) { |
| 1528 | ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) |
| 1529 | defer cancel() |
| 1530 | |
| 1531 | ts, _, err := c.dcli.CopyFromContainer(ctx, c.alphas[0].cid(), containerPath) |
| 1532 | if err != nil { |
| 1533 | return nil, errors.Wrapf(err, "error copying file from container [%v]", c.alphas[0].cname()) |
| 1534 | } |
| 1535 | defer ts.Close() |
| 1536 | |
| 1537 | tr := tar.NewReader(ts) |
| 1538 | if _, err := tr.Next(); err != nil { |
| 1539 | return nil, errors.Wrap(err, "error reading tar header") |
| 1540 | } |
| 1541 | data, err := io.ReadAll(tr) |
| 1542 | if err != nil { |
| 1543 | return nil, errors.Wrap(err, "error reading file contents from tar stream") |
| 1544 | } |
| 1545 | return data, nil |
| 1546 | } |
| 1547 | |
| 1548 | func (c *LocalCluster) CopyExportToHost(exportDir, hostDir string) (dataFiles, schemaFiles []string, err error) { |
| 1549 | ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) |