private void Open(string filename) { this._fs = new FileStream(filename, FileMode.Open); this._br = new BinaryReader(this._fs); this.Header = new TableHeader(); this.Header.BinRead(this._br); this.Columns = new List<Column>(); for (Int16 i = 0; i < this.Header.ColumnCount; i++) { Column c = new Column(); c.BinRead(_br); this.Columns.Add(c); } // Read mysterious extra byte; found in original test // table from a Lotus Approach database. _br.ReadByte(); // Sanity check row size if (this.CalculateTotalRowSize() != this.Header.RowLength) { throw new BadDataException("Total size of columns does not match that defined in the header"); } }
// <summary> // This method is intended to be used only when // creating a new table. So; e.g. not for normal writes. // </summary> public void CommitToDisk(string filename) { // Check that the file doesn't already exist if (File.Exists(filename)) { throw new InvalidOperationException("Commit is for writing new tables only; and the filename allocated for this table already exists"); } // Use a temporary handle, it will be re-opened when we retrieve from it using (FileStream newTableStream = new FileStream(filename, FileMode.CreateNew)) { BinaryWriter bw = new BinaryWriter(newTableStream); // Write the header this.Header = new TableHeader(); this.Header.Size = (short)((this.Columns.Count + 1) * 32); this.Header.RowCount = 0; this.Header.RowLength = (short)this.CalculateTotalRowSize(); this.Header.BinWrite(bw); foreach (Column c in this.Columns) { c.BinWrite(bw); } // Add mysterious extra byte bw.Write(new byte[1]); bw.Close(); } }