MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / Write

Method Write

pkg/userlog/plain/plainlogfile.go:57–86  ·  view source on GitHub ↗
(l *userlog.UserLog, buf []byte)

Source from the content-addressed store, hash-verified

55)
56
57func (f *plainLogFile) Write(l *userlog.UserLog, buf []byte) (int, error) {
58 w := f.writer
59 if w == nil {
60 return 0, errLogClosed
61 }
62 if f.capacity <= 0 {
63 return 0, errOverCapacity
64 }
65 tmp := bytes.NewBuffer(nil)
66 i, j := 0, 0
67 for i < len(buf) {
68 j = bytes.Index(buf[i:], LineByte)
69 if j < 0 {
70 j = len(buf)
71 } else if j > 0 {
72 j = i + j
73 } else {
74 i++
75 continue
76 }
77 tmp.WriteString(l.Created.UTC().Format(time.RFC3339))
78 tmp.WriteByte('\t')
79 tmp.Write(buf[i:j])
80 tmp.WriteByte('\n')
81 i = j + 1
82 }
83 w.Write(tmp.Bytes())
84 atomic.AddInt32(&f.capacity, int32(-i))
85 return i, nil
86}
87
88func (f *plainLogFile) Close() error {
89 w := f.writer

Callers

nothing calls this directly

Calls 4

WriteStringMethod · 0.80
WriteByteMethod · 0.80
BytesMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected