blob: bf55966a571fe93717ed6485b291a85b24c2b51b (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package loose
import (
"bytes"
"errors"
objectheader "codeberg.org/lindenii/furgit/object/header"
)
// acceptFull validates and accounts raw full-object input.
func (writer *streamWriter) acceptFull(src []byte) error {
if !writer.headerDone {
nul := bytes.IndexByte(src, 0)
if nul >= 0 {
headerChunkLen := nul + 1
writer.headerBuf = append(writer.headerBuf, src[:headerChunkLen]...)
_, size, _, ok := objectheader.Parse(writer.headerBuf)
if !ok {
return errors.New("objectstore/loose: malformed object header")
}
writer.headerDone = true
writer.expectedContentLeft = size
return writer.acceptContent(int64(len(src) - headerChunkLen))
}
writer.headerBuf = append(writer.headerBuf, src...)
return nil
}
return writer.acceptContent(int64(len(src)))
}
// acceptContent validates and accounts content byte counts.
func (writer *streamWriter) acceptContent(n int64) error {
if n > writer.expectedContentLeft {
return errors.New("objectstore/loose: object content exceeds declared size")
}
writer.expectedContentLeft -= n
return nil
}
// writeRawChunk forwards raw bytes to the hash and deflate pipeline.
func (writer *streamWriter) writeRawChunk(src []byte) error {
_, err := writer.hash.Write(src)
if err != nil {
return err
}
_, err = writer.zw.Write(src)
if err != nil {
return err
}
return nil
}
|