本文整理匯總了Golang中github.com/luci/luci-go/common/isolated.HexDigest類的典型用法代碼示例。如果您正苦於以下問題:Golang HexDigest類的具體用法?Golang HexDigest怎麽用?Golang HexDigest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了HexDigest類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Add
func (d *disk) Add(digest isolated.HexDigest, src io.Reader) error {
if !digest.Validate() {
return os.ErrInvalid
}
p := d.itemPath(digest)
dst, err := os.Create(p)
if err != nil {
return err
}
h := isolated.GetHash()
// TODO(maruel): Use a LimitedReader flavor that fails when reaching limit.
size, err := io.Copy(dst, io.TeeReader(src, h))
if err2 := dst.Close(); err == nil {
err = err2
}
if err != nil {
_ = os.Remove(p)
return err
}
if isolated.Sum(h) != digest {
_ = os.Remove(p)
return errors.New("invalid hash")
}
if common.Size(size) > d.policies.MaxSize {
_ = os.Remove(p)
return errors.New("item too large")
}
d.lock.Lock()
defer d.lock.Unlock()
d.lru.pushFront(digest, common.Size(size))
d.respectPolicies()
return nil
}
示例2: Evict
func (m *memory) Evict(digest isolated.HexDigest) {
if !digest.Validate() {
return
}
m.lock.Lock()
defer m.lock.Unlock()
delete(m.data, digest)
m.lru.pop(digest)
}
示例3: Read
func (d *disk) Read(digest isolated.HexDigest) (io.ReadCloser, error) {
if !digest.Validate() {
return nil, os.ErrInvalid
}
f, err := os.Open(d.itemPath(digest))
if err != nil {
return nil, err
}
return f, nil
}
示例4: Hardlink
func (m *memory) Hardlink(digest isolated.HexDigest, dest string, perm os.FileMode) error {
if !digest.Validate() {
return os.ErrInvalid
}
m.lock.Lock()
content, ok := m.data[digest]
m.lock.Unlock()
if !ok {
return os.ErrNotExist
}
return ioutil.WriteFile(dest, content, perm)
}
示例5: Touch
func (m *memory) Touch(digest isolated.HexDigest) bool {
if !digest.Validate() {
return false
}
m.lock.Lock()
defer m.lock.Unlock()
if _, ok := m.data[digest]; !ok {
return false
}
m.lru.touch(digest)
return true
}