func buildWithLoader()

in server/pkg/server/storage/backends/container/registry.go [156:191]


func buildWithLoader(u *url.URL, loader Loader) (storage.Engine, error) {
	// Initialize context
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	// Fetch bundle using loader
	br, errDriver := loader.Reader(ctx, u.Path)
	if errDriver != nil {
		return nil, fmt.Errorf("unable to load container content: %w", errDriver)
	}

	// Extract bundle container key form url
	var (
		q              = u.Query()
		containerIDRaw = q.Get("cid")
		unlockKeyRaw   = q.Get("unlock")
	)

	// Initialize bundle
	b, err := getBundle(ctx, br, containerIDRaw, unlockKeyRaw)
	if err != nil {
		return nil, fmt.Errorf("unable to extract bundle: %w", err)
	}

	// Initialize virtual filesystem
	bfs, err := fs.FromBundle(b)
	if err != nil {
		return nil, fmt.Errorf("unable to initialize bundle filesystem: %w", err)
	}

	// Build engine instance
	return &engine{
		u:  u,
		fs: bfs,
	}, nil
}