当前位置: 首页>>代码示例>>Golang>>正文


Golang Archive.WriteFile方法代码示例

本文整理汇总了Golang中kythe/io/kythe/go/platform/indexpack.Archive.WriteFile方法的典型用法代码示例。如果您正苦于以下问题:Golang Archive.WriteFile方法的具体用法?Golang Archive.WriteFile怎么用?Golang Archive.WriteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kythe/io/kythe/go/platform/indexpack.Archive的用法示例。


在下文中一共展示了Archive.WriteFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: fetchAndStore

// fetchAndStore reads the contents of path and stores them into a, returning
// the digest of the contents.  The path to digest mapping is cached so that
// repeated uses of the same file will avoid redundant work.
func (e *Extractor) fetchAndStore(ctx context.Context, path string, a *indexpack.Archive) (string, error) {
	if digest, ok := e.fmap[path]; ok {
		return digest, nil
	}
	data, err := vfs.ReadFile(ctx, path)
	if err != nil {
		// If there's an alternative installation path, and this is a path that
		// could potentially be there, try that.
		if i := strings.Index(path, "/pkg/"); i >= 0 && e.AltInstallPath != "" {
			alt := e.AltInstallPath + path[i:]
			data, err = vfs.ReadFile(ctx, alt)
			// fall through to the recheck below
		}
	}
	if err != nil {
		return "", err
	}
	name, err := a.WriteFile(ctx, data)
	if err != nil {
		return "", err
	}
	digest := strings.TrimSuffix(name, filepath.Ext(name))
	if e.fmap == nil {
		e.fmap = map[string]string{path: digest}
	}
	return digest, err
}
开发者ID:herberteuler,项目名称:kythe,代码行数:30,代码来源:golang.go

示例2: packIndex

func packIndex(ctx context.Context, pack *indexpack.Archive, idx *kindex.Compilation) error {
	for _, data := range idx.Files {
		if path, err := pack.WriteFile(ctx, data.Content); err != nil {
			return fmt.Errorf("error writing file %v: %v", data.Info, err)
		} else if !*quiet {
			log.Println("Wrote file to", path)
		}
	}

	path, err := pack.WriteUnit(ctx, formatKey, idx.Proto)
	if err != nil {
		return fmt.Errorf("error writing compilation unit: %v", err)
	}
	fmt.Println(strings.TrimSuffix(path, ".unit"))
	return nil
}
开发者ID:gameduell,项目名称:kythe,代码行数:16,代码来源:indexpack.go


注:本文中的kythe/io/kythe/go/platform/indexpack.Archive.WriteFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。