MCPcopy
hub / github.com/go-git/go-git / WriteHeader

Method WriteHeader

plumbing/format/objfile/writer.go:45–62  ·  view source on GitHub ↗

WriteHeader writes the type and the size and prepares to accept the object's contents. If an invalid t is provided, plumbing.ErrInvalidType is returned. If a negative size is provided, ErrNegativeSize is returned.

(t plumbing.ObjectType, size int64)

Source from the content-addressed store, hash-verified

43// contents. If an invalid t is provided, plumbing.ErrInvalidType is returned. If a
44// negative size is provided, ErrNegativeSize is returned.
45func (w *Writer) WriteHeader(t plumbing.ObjectType, size int64) error {
46 if !t.Valid() {
47 return plumbing.ErrInvalidType
48 }
49 if size < 0 {
50 return ErrNegativeSize
51 }
52
53 b := t.Bytes()
54 b = append(b, ' ')
55 b = append(b, []byte(strconv.FormatInt(size, 10))...)
56 b = append(b, 0)
57
58 defer w.prepareForWrite(t, size)
59 _, err := w.zlib.Write(b)
60
61 return err
62}
63
64func (w *Writer) prepareForWrite(t plumbing.ObjectType, size int64) {
65 w.pending = size

Callers 8

testWriterFunction · 0.95
TestWriteOverflowMethod · 0.95
SetEncodedObjectMethod · 0.80
TestNewObjectMethod · 0.80
TestIssue55Function · 0.80

Calls 4

prepareForWriteMethod · 0.95
ValidMethod · 0.80
BytesMethod · 0.45
WriteMethod · 0.45

Tested by 7

testWriterFunction · 0.76
TestWriteOverflowMethod · 0.76
TestNewObjectMethod · 0.64
TestIssue55Function · 0.64