public static void InsertFile(IndexNode node, Stream stream, Engine engine) { DataUnit dataPage = null; byte[] buffer = new byte[0xff8L]; uint totalBytes = 0; int read = 0; int dataPerPage = 0xff8; while ((read = stream.Read(buffer, 0, dataPerPage)) > 0) { totalBytes += (uint) read; if (dataPage == null) { dataPage = engine.GetPageData(node.DataPageID); } else { dataPage = GetNewDataPage(dataPage, engine); } if (!dataPage.IsEmpty) { throw new FileDBException("Page {0} is not empty", new object[] { dataPage.UnitID }); } Array.Copy(buffer, dataPage.DataBlock, read); dataPage.IsEmpty = false; dataPage.DataBlockLength = (short) read; } if (dataPage.NextUnitID != uint.MaxValue) { engine.Header.FreeDataPageID = dataPage.NextUnitID; dataPage.NextUnitID = uint.MaxValue; } UnitFactory.WriteToFile(dataPage, engine.Writer); node.FileLength = totalBytes; }
internal EntryInfo(IndexNode node) { this._id = node.ID; this._fileName = node.FileName + "." + node.FileExtension; this._mimeType = MimeTypeConverter.Convert(node.FileExtension); this._fileLength = node.FileLength; }
private static IndexNode BinaryInsertNode(IndexLink baseLink, IndexNode baseNode, EntryInfo entry, Engine engine) { IndexUnit pageIndex = engine.GetFreeIndexPage(); IndexNode newNode = pageIndex.Nodes[pageIndex.NodeIndex]; baseLink.PageID = pageIndex.UnitID; baseLink.Index = pageIndex.NodeIndex; newNode.UpdateFromEntry(entry); newNode.DataPageID = DataFactory.GetStartDataPageID(engine); if (pageIndex.UnitID != baseNode.IndexPage.UnitID) { engine.CacheIndexPage.AddPage(baseNode.IndexPage, true); } engine.CacheIndexPage.AddPage(pageIndex, true); return newNode; }
public static IndexNode BinaryInsert(EntryInfo target, IndexNode baseNode, Engine engine) { int dif = baseNode.ID.CompareTo(target.ID); if (dif == 1) { if (baseNode.Right.IsEmpty) { return BinaryInsertNode(baseNode.Right, baseNode, target, engine); } return BinaryInsert(target, GetChildIndexNode(baseNode.Right, engine), engine); } if (dif != -1) { throw new FileDBException("Same GUID?!?"); } if (baseNode.Left.IsEmpty) { return BinaryInsertNode(baseNode.Left, baseNode, target, engine); } return BinaryInsert(target, GetChildIndexNode(baseNode.Left, engine), engine); }
public static IndexNode BinarySearch(Guid target, IndexNode baseNode, Engine engine) { int dif = baseNode.ID.CompareTo(target); if (dif == 1) { if (baseNode.Right.IsEmpty) { return null; } return BinarySearch(target, GetChildIndexNode(baseNode.Right, engine), engine); } if (dif != -1) { return baseNode; } if (baseNode.Left.IsEmpty) { return null; } return BinarySearch(target, GetChildIndexNode(baseNode.Left, engine), engine); }
public static void ReadFile(IndexNode node, Stream stream, Engine engine) { DataUnit dataPage = UnitFactory.GetDataPage(node.DataPageID, engine.Reader, false); while (dataPage != null) { stream.Write(dataPage.DataBlock, 0, dataPage.DataBlockLength); if (dataPage.NextUnitID == uint.MaxValue) { dataPage = null; } else { dataPage = UnitFactory.GetDataPage(dataPage.NextUnitID, engine.Reader, false); } } }