MCPcopy Create free account
hub / github.com/github/copilot-sdk / Write

Method Write

go/internal/truncbuffer/truncbuffer.go:27–49  ·  view source on GitHub ↗

Write appends p to the buffer, keeping only the last size bytes. The return value n is the length of p;

(p []byte)

Source from the content-addressed store, hash-verified

25// Write appends p to the buffer, keeping only the last size bytes.
26// The return value n is the length of p;
27func (t *TruncBuffer) Write(p []byte) (int, error) {
28 t.mu.Lock()
29 defer t.mu.Unlock()
30
31 // If input is larger than the buffer, only keep the tail.
32 if len(p) >= t.size {
33 copy(t.buf, p[len(p)-t.size:])
34 t.head = 0
35 t.full = true
36 return len(p), nil
37 }
38
39 for _, b := range p {
40 t.buf[t.head] = b
41 t.head++
42 if t.head == t.size {
43 t.head = 0
44 t.full = true
45 }
46 }
47
48 return len(p), nil
49}
50
51// Bytes returns a copy of the current buffer contents in order.
52func (t *TruncBuffer) Bytes() []byte {

Calls

no outgoing calls