本文整理汇总了Golang中gopkg/in/src-d/go-git/v4/plumbing.Object.Reader方法的典型用法代码示例。如果您正苦于以下问题:Golang Object.Reader方法的具体用法?Golang Object.Reader怎么用?Golang Object.Reader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gopkg/in/src-d/go-git/v4/plumbing.Object
的用法示例。
在下文中一共展示了Object.Reader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ApplyDelta
// ApplyDelta writes to taget the result of applying the modification deltas in delta to base.
func ApplyDelta(target, base plumbing.Object, delta []byte) error {
r, err := base.Reader()
if err != nil {
return err
}
w, err := target.Writer()
if err != nil {
return err
}
src, err := ioutil.ReadAll(r)
if err != nil {
return err
}
dst := PatchDelta(src, delta)
target.SetSize(int64(len(dst)))
if _, err := w.Write(dst); err != nil {
return err
}
return nil
}
示例2: SetObject
// Set adds a new object to the storage.
func (s *ObjectStorage) SetObject(o plumbing.Object) (plumbing.Hash, error) {
if o.Type() == plumbing.OFSDeltaObject || o.Type() == plumbing.REFDeltaObject {
return plumbing.ZeroHash, plumbing.ErrInvalidType
}
ow, err := s.dir.NewObject()
if err != nil {
return plumbing.ZeroHash, err
}
defer ow.Close()
or, err := o.Reader()
if err != nil {
return plumbing.ZeroHash, err
}
defer or.Close()
if err := ow.WriteHeader(o.Type(), o.Size()); err != nil {
return plumbing.ZeroHash, err
}
if _, err := io.Copy(ow, or); err != nil {
return plumbing.ZeroHash, err
}
return o.Hash(), nil
}
示例3: SetObject
func (s *Storage) SetObject(obj plumbing.Object) (plumbing.Hash, error) {
key, err := s.buildKey(obj.Hash(), obj.Type())
if err != nil {
return obj.Hash(), err
}
r, err := obj.Reader()
if err != nil {
return obj.Hash(), err
}
c, err := ioutil.ReadAll(r)
if err != nil {
return obj.Hash(), err
}
bins := driver.BinMap{
urlField: s.url,
"hash": obj.Hash().String(),
"type": obj.Type().String(),
"blob": c,
}
err = s.client.Put(nil, key, bins)
return obj.Hash(), err
}
示例4: Decode
// Decode transforms a plumbing.Object into a Tag struct.
func (t *Tag) Decode(o plumbing.Object) (err error) {
if o.Type() != plumbing.TagObject {
return ErrUnsupportedObject
}
t.Hash = o.Hash()
reader, err := o.Reader()
if err != nil {
return err
}
defer checkClose(reader, &err)
r := bufio.NewReader(reader)
for {
line, err := r.ReadSlice('\n')
if err != nil && err != io.EOF {
return err
}
line = bytes.TrimSpace(line)
if len(line) == 0 {
break // Start of message
}
split := bytes.SplitN(line, []byte{' '}, 2)
switch string(split[0]) {
case "object":
t.Target = plumbing.NewHash(string(split[1]))
case "type":
t.TargetType, err = plumbing.ParseObjectType(string(split[1]))
if err != nil {
return err
}
case "tag":
t.Name = string(split[1])
case "tagger":
t.Tagger.Decode(split[1])
}
if err == io.EOF {
return nil
}
}
data, err := ioutil.ReadAll(r)
if err != nil {
return err
}
t.Message = string(data)
return nil
}