MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Write

Method Write

internal/caches/writer_memory.go:67–94  ·  view source on GitHub ↗

Write 写入数据

(data []byte)

Source from the content-addressed store, hash-verified

65
66// Write 写入数据
67func (this *MemoryWriter) Write(data []byte) (n int, err error) {
68 var l = len(data)
69 if l == 0 {
70 return
71 }
72
73 if this.item.IsPrepared {
74 if this.item.WriteOffset+int64(l) > this.expectedBodySize {
75 err = ErrWritingUnavailable
76 return
77 }
78 copy(this.item.BodyValue[this.item.WriteOffset:], data)
79 this.item.WriteOffset += int64(l)
80 } else {
81 this.item.BodyValue = append(this.item.BodyValue, data...)
82 }
83
84 this.bodySize += int64(l)
85
86 // 检查尺寸
87 if this.maxSize > 0 && this.bodySize > this.maxSize {
88 err = ErrEntityTooLarge
89 this.storage.IgnoreKey(this.key, this.maxSize)
90 return l, err
91 }
92
93 return l, nil
94}
95
96// WriteAt 在指定位置写入数据
97func (this *MemoryWriter) WriteAt(offset int64, b []byte) error {

Callers

nothing calls this directly

Calls 1

IgnoreKeyMethod · 0.65

Tested by

no test coverage detected