 
 // Concept requirements & implementation
 
+// A block contains a header and data
+
 // CRUD D
 // - generic data
 // - generic header

        return pos!;
    }
    
    // READ
        
    func readData() -> D! {
        
        var data = self.fileHandle.readDataOfLength(sizeof(D)); //return NSData
        
        // works only by value?
        if data {
            var buffer : CMutablePointer<D> = nil
            data.getBytes(&buffer)
            
            let result = buffer.withUnsafePointer {p in
                p.memory
            }
            
            return result;
        }
        
        return nil;
    }
    
    // UPDATE
    
    func writeData(data: D, atPos pos: CUnsignedLongLong) {
        
        // TODO: FIX
        var a = data
        let buffer = NSData(bytesNoCopy:&a, length:sizeof(D), freeWhenDone:false)
        
        self.fileHandle.seekToFileOffset(pos)
        self.writeHeader(forData: &a, atPos: pos)
        
        writeData(buffer)
    }
    
    func writeData(data: NSData) {
        self.fileHandle.writeData(data);
    }
    
    // subclases have to override
    func deleteData(aID: UID) -> CUnsignedLongLong {
        
        var pos = self.seekToFileID(aID)
        
        var header = H()
        header.used = false
        
        self.writeHeader(&header)
        
        self.unusedDataSegments[pos] = true
        
        return pos
    }
        
}
        
        return pos
    }
    
    // basic block methodes
    subscript(index: UID) -> D! {
        get {
            return self.readBlock(index)
        }
        
        set (newValue) {
            
            let pos = calculatePos(index)
            
            if newValue {
                if (pos > endOfFile) {
                    // TODO: error
                } else {
                    writeBlock(newValue, atPos: pos)
                }
                
            } else {
                // newValue = nil -> delete
                deleteBlock(index)
            }
        }
    }
    
    // #pragma mark READ -------------------------------------------------------
    

    func readBlock(index : UID) -> D! {
        self.seekToFileID(index)
        
        let header = readHeader()
        if (header.used) {
            return self.readData()
        }
        
        return nil;
    }
    
    // #pragma mark - read/write header
    
    func readHeader() -> H! {
