Hello, I am working with a binary file. What I’m trying to do is write a slice to the file, and then read it to check that everything is fine. However, when reading the file, I get an error
which says ‘Unexpected EOF’. The offset within the disk is correct, the end of the file has not been reached, however the error occurs. What can be?
func initializeBMInode(ptrDisk *os.File, numStructs, iniBitmap int64) {
total := 5 * numStructs
for i := int64(0); i < total; i++ {
ctr := '0'
ptrDisk.Seek(iniBitmap+i, 0)
var buffer bytes.Buffer
binary.Write(&buffer, binary.BigEndian, &ctr)
writeNextBytes(ptrDisk, buffer.Bytes())
}
/*
Test bitmap
*/
bmGen := make([]byte, 5*numStructs)
ptrDisk.Seek(iniBitmap, 0)
fmt.Println("InitBitmap")
fmt.Println(iniBitmap)
content := readNextBytes(ptrDisk, int64(unsafe.Sizeof(bmGen)))
buffer := bytes.NewBuffer(content)
err := binary.Read(buffer, binary.BigEndian, &bmGen)
if err != nil {
log.Fatal(err) // Get error
}
fmt.Println(bmGen)
}