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

Method Write

internal/utils/bfs/blocks_file.go:106–143  ·  view source on GitHub ↗
(hash string, blockType BlockType, b []byte, originOffset int64)

Source from the content-addressed store, hash-verified

104}
105
106func (this *BlocksFile) Write(hash string, blockType BlockType, b []byte, originOffset int64) (n int, err error) {
107 if len(b) == 0 {
108 return
109 }
110
111 this.mu.Lock()
112 defer this.mu.Unlock()
113
114 posBefore, err := this.currentPos()
115 if err != nil {
116 return 0, err
117 }
118
119 err = this.checkStatus()
120 if err != nil {
121 return
122 }
123
124 AckWriteThread()
125 n, err = this.fp.Write(b)
126 ReleaseWriteThread()
127
128 if err == nil {
129 if n > 0 {
130 this.writtenBytes += int64(n)
131 }
132
133 if blockType == BlockTypeHeader {
134 err = this.mFile.WriteHeaderBlockUnsafe(hash, posBefore, posBefore+int64(n))
135 } else if blockType == BlockTypeBody {
136 err = this.mFile.WriteBodyBlockUnsafe(hash, posBefore, posBefore+int64(n), originOffset, originOffset+int64(n))
137 } else {
138 err = errors.New("invalid block type '" + string(blockType) + "'")
139 }
140 }
141
142 return
143}
144
145func (this *BlocksFile) OpenFileWriter(fileHash string, bodySize int64, isPartial bool) (writer *FileWriter, err error) {
146 err = CheckHashErr(fileHash)

Callers

nothing calls this directly

Calls 9

currentPosMethod · 0.95
checkStatusMethod · 0.95
AckWriteThreadFunction · 0.85
ReleaseWriteThreadFunction · 0.85
WriteBodyBlockUnsafeMethod · 0.80
WriteMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected