public void Pack(FileInfo archiveFile, DirectoryInfo rootDir) { var rootRecord = ScanDirectory(rootDir); var memoryStream = new MemoryStream(); Persistance.Write(memoryStream, rootRecord); var listingBytes = memoryStream.ToArray(); long listingSize = listingBytes.LongLength; long payloadSize = currentOffset; long payloadOffset = IntegerUtils.NextLargerMultiple(HeaderSize + listingSize, OffsetGranularity); long totalSize = payloadOffset + payloadSize; using (var archiveMap = MemoryMappedFile.CreateFromFile(archiveFile.FullName, FileMode.Create, archiveFile.Name, totalSize)) { //write header using (var headerAccessor = archiveMap.CreateViewAccessor(0, HeaderSize)) { headerAccessor.Write(0, listingSize); headerAccessor.Write(sizeof(long), payloadOffset); } //write listing using (var listingAccessor = archiveMap.CreateViewAccessor(HeaderSize, listingSize)) { listingAccessor.WriteArray(0, listingBytes, 0, listingBytes.Length); } WriteDirectory(archiveMap, payloadOffset, rootRecord, rootDir); } }
public void TestNextLargerMultiple() { Assert.AreEqual(0, IntegerUtils.NextLargerMultiple(0, 3)); Assert.AreEqual(3, IntegerUtils.NextLargerMultiple(1, 3)); Assert.AreEqual(3, IntegerUtils.NextLargerMultiple(2, 3)); Assert.AreEqual(3, IntegerUtils.NextLargerMultiple(3, 3)); Assert.AreEqual(6, IntegerUtils.NextLargerMultiple(4, 3)); Assert.AreEqual(6, IntegerUtils.NextLargerMultiple(5, 3)); }
public ConstantBufferManager(Device device) { this.buffer = new SharpDX.Direct3D11.Buffer(device, IntegerUtils.NextLargerMultiple(SizeOfTInBytes, 16), ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0); }
private void IncrementOffset(long size) { currentOffset = IntegerUtils.NextLargerMultiple(currentOffset + size, OffsetGranularity); }