本文整理匯總了Golang中labix/org/v2/mgo.GridFile.GetMeta方法的典型用法代碼示例。如果您正苦於以下問題:Golang GridFile.GetMeta方法的具體用法?Golang GridFile.GetMeta怎麽用?Golang GridFile.GetMeta使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類labix/org/v2/mgo.GridFile
的用法示例。
在下文中一共展示了GridFile.GetMeta方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Copy
func (s *mongodbStorage) Copy(localName, remoteName string, toRemote bool, checksum, moduleType string) (stat *contester_proto.FileStat, err error) {
ec := tools.ErrorContext("mongodb.Copy")
if toRemote {
stat, err = tools.StatFile(localName, true)
if err != nil {
err = ec.NewError(err, "local.CalculateChecksum")
}
// If file doesn't exist then stat == nil.
if err != nil || stat == nil {
return
}
if checksum != "" && *stat.Checksum != checksum {
return nil, ec.NewError(fmt.Errorf("Checksum mismatch, local %s != %s", stat.Checksum, checksum))
}
checksum = *stat.Checksum
}
var local *os.File
if toRemote {
local, err = os.Open(localName)
} else {
local, err = os.Create(localName)
}
if err != nil {
return nil, ec.NewError(err, "local.Open")
}
defer local.Close()
var remote *mgo.GridFile
if toRemote {
// Remove all files with the same remoteName.
if err = s.GridFS.Remove(remoteName); err != nil {
return nil, ec.NewError(err, "remote.Remove")
}
remote, err = s.GridFS.Create(remoteName)
} else {
remote, err = s.GridFS.Open(remoteName)
}
if err != nil {
return nil, ec.NewError(err, "remote.Open")
}
defer remote.Close()
var source io.ReadCloser
if toRemote {
source = local
} else {
source = remote
var meta fileMetadata
if err = remote.GetMeta(&meta); err != nil {
return nil, ec.NewError(err, "remote.GetMeta")
}
if meta.CompressionType == "ZLIB" {
source, err = zlib.NewReader(source)
if err != nil {
return nil, ec.NewError(err, "zlib.NewReader")
}
}
}
var destination io.WriteCloser
if toRemote {
destination = zlib.NewWriter(remote)
} else {
destination = local
}
size, err := io.Copy(destination, source)
if err != nil {
return nil, ec.NewError(err, "io.Copy")
}
if toRemote {
var meta fileMetadata
meta.OriginalSize = uint64(size)
meta.CompressionType = "ZLIB"
meta.Checksum = *stat.Checksum
meta.ModuleType = moduleType
remote.SetMeta(meta)
}
if err = destination.Close(); err != nil {
return nil, ec.NewError(err, "destination.Close")
}
if err = source.Close(); err != nil {
return nil, ec.NewError(err, "source.Close")
}
if !toRemote {
stat, err = tools.StatFile(localName, true)
if err != nil {
return nil, ec.NewError(err, "StatFile")
}
}
//.........這裏部分代碼省略.........