code: func memoryMapAndGenerate(path string, size uint64, generator func(buffer []uint32)) (*os.File, mmap.MMap, []uint32, error) {
  	// Ensure the data folder exists
  	if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
  		return nil, nil, nil, err
  	}
  	// Create a huge temporary empty file to fill with data
  	temp := path + "." + strconv.Itoa(rand.Int())
  
  	dump, err := os.Create(temp)
  	if err != nil {
  		return nil, nil, nil, err
  	}
  	if err = dump.Truncate(int64(len(dumpMagic))*4 + int64(size)); err != nil {
  		return nil, nil, nil, err
  	}
  	// Memory map the file for writing and fill it with the generator
  	mem, buffer, err := memoryMapFile(dump, true)
  	if err != nil {
  		dump.Close()
  		return nil, nil, nil, err
  	}
  	copy(buffer, dumpMagic)
  
  	data := buffer[len(dumpMagic):]
  	generator(data)
  
  	if err := mem.Unmap(); err != nil {
  		return nil, nil, nil, err
  	}
  	if err := dump.Close(); err != nil {
  		return nil, nil, nil, err
  	}
  	if err := os.Rename(temp, path); err != nil {
  		return nil, nil, nil, err
  	}
  	return memoryMap(path)
  }
docs: // memoryMapAndGenerate tries to memory map a temporary file of uint32s for write
  // access, fill it with the data from a generator and then move it into the final
  // path requested.