/// <summary> /// 获取该文件保存的所有版本信息 /// </summary> /// <param name="breakMatch">终止读取版本信息的判断</param> /// <returns></returns> public VersionSnippet[] GetAllVersionsWithBreak(Predicate <VersionSnippet> breakMatch) { List <VersionSnippet> vers = new List <VersionSnippet>(); uint tVer = GetMaxVersion(_internalReader); //最后修改版本 _internalReader.BaseStream.Seek(NEXT_WRITEINDEX_OFFSET + 5, SeekOrigin.Begin); //第一个版本索引位置 uint cVer = _internalReader.ReadUInt32(); VersionSnippet snippet; bool midBreaked = false; while (cVer != tVer) { snippet = new VersionSnippet(); snippet.Version = cVer; snippet.CreateTimeUTC = DateTime.FromBinary(_internalReader.ReadInt64()); snippet.StoreIndex = _internalReader.ReadInt64(); snippet.FileLength = _internalReader.ReadInt64(); vers.Add(snippet); if (breakMatch != null && breakMatch(snippet)) { midBreaked = true; break; } cVer = _internalReader.ReadUInt32(); } if (cVer == tVer && midBreaked == false) { snippet = new VersionSnippet(); snippet.Version = cVer; snippet.CreateTimeUTC = DateTime.FromBinary(_internalReader.ReadInt64()); snippet.StoreIndex = _internalReader.ReadInt64(); snippet.FileLength = _internalReader.ReadInt64(); vers.Add(snippet); } return(vers.ToArray()); }
/// <summary> /// 获取指定版本的二进制字节数据 /// </summary> /// <param name="version">文件版本</param> /// <returns>该文件二进制字节数据,如果指定版本不存在则长度为0的字节数组。</returns> public byte[] ReadReversion(uint ver) { //获取最高版本 uint maxVer = GetMaxVersion(_internalReader); //最后修改版本 int offSet = GetOffSetDat <int>(_internalReader, DATA_INDEX_OFFSET); //Console.WriteLine("OffSET:{0}", offSet); long fIdx = 0, fLen = 0; if (ver == 0 || ver >= maxVer) { //最高版本数据的数据长度 _internalReader.BaseStream.Seek((long)(LASTED_VERSION_OFFSET + 4), SeekOrigin.Begin); fLen = _internalReader.ReadInt64(); int fLenIdx = _internalReader.ReadInt32(); _internalReader.BaseStream.Seek(fLenIdx - 16, SeekOrigin.Begin); fIdx = _internalReader.ReadInt64(); } else { //当版本高于检索版本时终止 VersionSnippet[] verDat = GetAllVersionsWithBreak(spt => (spt.Version > ver)); VersionSnippet lastMV = verDat[verDat.Length - 1]; //目标版本处在大于下一小版本且小于终止版本时,获取下一小版本 if (lastMV.Version > ver && verDat.Length >= 2) { lastMV = verDat[verDat.Length - 2]; } fIdx = lastMV.StoreIndex; fLen = lastMV.FileLength; } fIdx += offSet; return(base.ReadData(fIdx, (int)fLen)); }