(hash string, blockType BlockType, b []byte, originOffset int64)
| 104 | } |
| 105 | |
| 106 | func (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 | |
| 145 | func (this *BlocksFile) OpenFileWriter(fileHash string, bodySize int64, isPartial bool) (writer *FileWriter, err error) { |
| 146 | err = CheckHashErr(fileHash) |
nothing calls this directly
no test coverage detected