Flush flushes the index entry to the target file.
()
| 194 | |
| 195 | // Flush flushes the index entry to the target file. |
| 196 | func (ix *IndexWriter) Flush() { |
| 197 | ix.addName("") |
| 198 | |
| 199 | var off [5]uint32 |
| 200 | ix.main.writeString(magic) |
| 201 | off[0] = ix.main.offset() |
| 202 | for _, p := range ix.paths { |
| 203 | ix.main.writeString(p) |
| 204 | ix.main.writeString("\x00") |
| 205 | } |
| 206 | ix.main.writeString("\x00") |
| 207 | off[1] = ix.main.offset() |
| 208 | copyFile(ix.main, ix.nameData) |
| 209 | off[2] = ix.main.offset() |
| 210 | ix.mergePost(ix.main) |
| 211 | off[3] = ix.main.offset() |
| 212 | copyFile(ix.main, ix.nameIndex) |
| 213 | off[4] = ix.main.offset() |
| 214 | copyFile(ix.main, ix.postIndex) |
| 215 | for _, v := range off { |
| 216 | ix.main.writeUint32(v) |
| 217 | } |
| 218 | ix.main.writeString(trailerMagic) |
| 219 | |
| 220 | os.Remove(ix.nameData.name) |
| 221 | for _, f := range ix.postFile { |
| 222 | os.Remove(f.Name()) |
| 223 | } |
| 224 | os.Remove(ix.nameIndex.name) |
| 225 | os.Remove(ix.postIndex.name) |
| 226 | |
| 227 | log.Printf("%d data bytes, %d index bytes", ix.totalBytes, ix.main.offset()) |
| 228 | |
| 229 | ix.main.flush() |
| 230 | } |
| 231 | |
| 232 | func copyFile(dst, src *bufWriter) { |
| 233 | dst.flush() |