 
 // 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
    }
        
}
// D = a data 


class DataStore<H: DataStoreHeader,D: Init>  {
    
    // #pragma mark ----------------------------------------------------------------
    
    // data.length + header.length;
    let headerSize = sizeof(H)
    let dataSize = sizeof(D)
    let blockSize = sizeof(H) + sizeof(D)  // test as CUnsignedLongLong
    
    var error: NSError?  // readonly?
    
    var url: NSURL!
    var fileHandle: NSFileHandle!
    var newFile = false;
    
    var fileOffset : Int = 1  // see createNewFile
    
    var endOfFile: CUnsignedLongLong = 0;
    var unusedDataSegments =  Dictionary<CUnsignedLongLong,Bool>()
