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)
| 43 | // contents. If an invalid t is provided, plumbing.ErrInvalidType is returned. If a |
| 44 | // negative size is provided, ErrNegativeSize is returned. |
| 45 | func (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 | |
| 64 | func (w *Writer) prepareForWrite(t plumbing.ObjectType, size int64) { |
| 65 | w.pending = size |