public DonkeyRegion(File hardFile) {
        this.hardFile = hardFile;

        try {
            if (hardFile.exists()) {
                lastModification = hardFile.lastModified();
            }

            file = new RandomAccessFile(hardFile, "rw");
            if (file.length() < 5) {
                // Write the Donkeychunk magic
                file.writeByte(0x44);
                file.writeByte(0x4e);
                file.writeByte(0x4b);
                // Write the version
                file.writeByte(version);
                // Write the default flags
                file.writeByte(getFlags());
            }

            if (file.length() < 7173) {
                // Write a blank location map
                file.write(new byte[7168]);
            }

            file.seek(0L);

            if (!(file.readByte() == 0x44 && file.readByte() == 0x4e && file.readByte() == 0x4b)) {
                throw new NotADonkeyException("Donkeychunk signature invalid");
            }

            version = file.readByte();
            if (version > DonkeyConstants.DONKEY_VERSION) {
                throw new UnsupportedDonkeyException("Unsupported Donkeychunk version (region: " + version + ", library: " + DonkeyConstants.DONKEY_VERSION + ")");
            }

            byte flags = file.readByte();
            hasChunkTimestamps = (flags & 15) > 7;
            hasChunkCompression = (flags >> 4 & 15) > 7;
        } catch (IOException ex) {
            throw new NotADonkeyException(ex);
        }
    }