/// <summary> /// reads an OnDiscAdress from the index. /// </summary> /// <param name="NumberOfAdress">is the number of the OnDiscAdress to be read</param> /// <returns></returns> public OnDiscAdress ReadOnDiscAdress(long NumberOfAdress) { //byte[] Readin; lock (DatabaseIndexFile) { // check if this is even possible... if (DatabaseIndexFile.Length <= NumberOfAdress * 33) { return(null); } // seek to the multiple of NumberOfAdress DatabaseIndexFile.Seek(NumberOfAdress * 33, SeekOrigin.Begin); byte[] _SerializedData; OnDiscAdress _deserializedAdress; try { _SerializedData = new byte[33]; // todo: maybe a read cache might be great, to read more bytes sequential DatabaseIndexFile.Read(_SerializedData, 0, 33); _deserializedAdress = new OnDiscAdress(); _reader.Data = _SerializedData; _deserializedAdress.Deserialize(ref _reader); return(_deserializedAdress); } catch (Exception) { return(null); } } }
/// <summary> /// writes a new chunk of data to the disk (and index) /// </summary> /// <param name="Data">the byte array with the data</param> public void Write(byte[] Data) { // write the data to the database file OnDiscAdress adress = WriteToDatabase(Data); // and the adress to the index WriteToIndex(adress); }
public byte[] ReadData(OnDiscAdress Adress) { byte[] Readin; lock (DatabaseFile) { // seek to the position DatabaseFile.Seek(Adress.Start, SeekOrigin.Begin); Readin = new byte[Adress.End - Adress.Start]; // read it in DatabaseFile.Read(Readin, 0, Readin.Length); } return Readin; }
public byte[] ReadData(OnDiscAdress Adress) { byte[] Readin; lock (DatabaseFile) { // seek to the position DatabaseFile.Seek(Adress.Start, SeekOrigin.Begin); Readin = new byte[Adress.End - Adress.Start]; // read it in DatabaseFile.Read(Readin, 0, Readin.Length); } return(Readin); }
private void WriteToIndex(OnDiscAdress Adresspattern) { lock (DatabaseIndexFile) { // seek to the end... DatabaseIndexFile.Seek(DatabaseIndexFile.Length, SeekOrigin.Begin); // re-use the writer _writer.ResetBuffer(); // serialize the index... byte[] ToWrite = Adresspattern.SerializeAligned(ref _writer); DatabaseIndexFile.Write(ToWrite, 0, ToWrite.Length); if (FlushOnWrite) { DatabaseIndexFile.Flush(); } } }
private OnDiscAdress WriteToDatabase(byte[] ToWrite) { OnDiscAdress OutputAdress = new OnDiscAdress(); lock (DatabaseFile) { // seek to the end... DatabaseFile.Seek(DatabaseFile.Length, SeekOrigin.Begin); OutputAdress.Start = DatabaseFile.Position; DatabaseFile.Write(ToWrite, 0, ToWrite.Length); OutputAdress.End = DatabaseFile.Position; if (FlushOnWrite) { DatabaseFile.Flush(); } } return(OutputAdress); }
private void WriteToIndex(OnDiscAdress Adresspattern) { lock (DatabaseIndexFile) { // seek to the end... DatabaseIndexFile.Seek(DatabaseIndexFile.Length, SeekOrigin.Begin); // re-use the writer _writer.ResetBuffer(); // serialize the index... byte[] ToWrite = Adresspattern.SerializeAligned(ref _writer); DatabaseIndexFile.Write(ToWrite, 0, ToWrite.Length); if (FlushOnWrite) DatabaseIndexFile.Flush(); } }
private OnDiscAdress WriteToDatabase(byte[] ToWrite) { OnDiscAdress OutputAdress = new OnDiscAdress(); lock (DatabaseFile) { // seek to the end... DatabaseFile.Seek(DatabaseFile.Length, SeekOrigin.Begin); OutputAdress.Start = DatabaseFile.Position; DatabaseFile.Write(ToWrite, 0, ToWrite.Length); OutputAdress.End = DatabaseFile.Position; if (FlushOnWrite) DatabaseFile.Flush(); } return OutputAdress; }
/// <summary> /// reads an OnDiscAdress from the index. /// </summary> /// <param name="NumberOfAdress">is the number of the OnDiscAdress to be read</param> /// <returns></returns> public OnDiscAdress ReadOnDiscAdress(long NumberOfAdress) { byte[] Readin; lock (DatabaseIndexFile) { // check if this is even possible... if (DatabaseIndexFile.Length <= NumberOfAdress * 33) return null; // seek to the multiple of NumberOfAdress DatabaseIndexFile.Seek(NumberOfAdress * 33, SeekOrigin.Begin); byte[] _SerializedData; OnDiscAdress _deserializedAdress; try { _SerializedData = new byte[33]; // todo: maybe a read cache might be great, to read more bytes sequential DatabaseIndexFile.Read(_SerializedData, 0, 33); _deserializedAdress = new OnDiscAdress(); _reader.Data = _SerializedData; _deserializedAdress.Deserialize(ref _reader); return _deserializedAdress; } catch (Exception) { return null; } } }