本文整理汇总了Golang中github.com/APTrust/exchange/models.GenericFile.IngestMd5方法的典型用法代码示例。如果您正苦于以下问题:Golang GenericFile.IngestMd5方法的具体用法?Golang GenericFile.IngestMd5怎么用?Golang GenericFile.IngestMd5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/APTrust/exchange/models.GenericFile
的用法示例。
在下文中一共展示了GenericFile.IngestMd5方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: saveWithChecksums
// buildFile saves a data file from the tar archive to disk,
// then returns a struct with data we'll need to construct the
// GenericFile object in Fedora later.
func (reader *Reader) saveWithChecksums(gf *models.GenericFile) {
// Set up a MultiWriter to stream data ONCE to file,
// md5 and sha256. We don't want to process the stream
// three separate times.
err := os.MkdirAll(filepath.Dir(gf.IngestLocalPath), 0755)
if err != nil {
gf.IngestErrorMessage = err.Error()
return
}
outputWriter, err := os.OpenFile(gf.IngestLocalPath, os.O_CREATE|os.O_WRONLY, 0644)
if outputWriter != nil {
defer outputWriter.Close()
}
if err != nil {
gf.IngestErrorMessage = fmt.Sprintf("Error opening %s for writing: %v", gf.IngestLocalPath, err)
return
}
md5Hash := md5.New()
shaHash := sha256.New()
multiWriter := io.MultiWriter(md5Hash, shaHash, outputWriter)
io.Copy(multiWriter, reader.tarReader)
gf.IngestMd5 = fmt.Sprintf("%x", md5Hash.Sum(nil))
gf.IngestSha256 = fmt.Sprintf("%x", shaHash.Sum(nil))
gf.IngestSha256GeneratedAt = time.Now().UTC()
gf.FileFormat, _ = platform.GuessMimeType(gf.IngestLocalPath) // on err, defaults to application/binary
return
}