private void WriteFileData(BuilderContext context) { Stream outStream = context.RawStream; bool disposeSource = false; try { if (_source == null) { var locator = new LocalFileLocator(string.Empty); _source = locator.Open(_sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read); disposeSource = true; } if (_source.Position != 0) { _source.Position = 0; } long startPos = outStream.Position; int bufferedBytes = StreamUtilities.ReadMaximum(_source, context.IoBuffer, 0, context.DataBlockSize); if (bufferedBytes < context.DataBlockSize) { // Fragment - less than one complete block of data _inode.StartBlock = 0xFFFFFFFF; _inode.FragmentKey = context.WriteFragment(bufferedBytes, out _inode.FragmentOffset); _inode.FileSize = (uint)bufferedBytes; } else { // At least one full block, no fragments used _inode.FragmentKey = 0xFFFFFFFF; _lengths = new List <uint>(); _inode.StartBlock = (uint)startPos; _inode.FileSize = bufferedBytes; while (bufferedBytes > 0) { _lengths.Add(context.WriteDataBlock(context.IoBuffer, 0, bufferedBytes)); bufferedBytes = StreamUtilities.ReadMaximum(_source, context.IoBuffer, 0, context.DataBlockSize); _inode.FileSize += (uint)bufferedBytes; } } } finally { if (disposeSource) { _source.Dispose(); } } }
private void NextBlock() { long position = _context.RawStream.Position; uint writeLen = _context.WriteDataBlock(_currentBlock, 0, _currentOffset); FragmentRecord blockRecord = new FragmentRecord { StartBlock = position, CompressedSize = (int)writeLen }; _fragmentBlocks.Add(blockRecord); }
private void WriteFileData(BuilderContext context) { Stream outStream = context.RawStream; bool disposeSource = false; try { if (_source == null) { _source = new FileStream(_sourcePath, FileMode.Open, FileAccess.Read, FileShare.Read); disposeSource = true; } if (_source.Position != 0) { _source.Position = 0; } long startPos = outStream.Position; int bufferedBytes = Utilities.ReadFully(_source, context.IoBuffer, 0, context.DataBlockSize); if (bufferedBytes < context.DataBlockSize) { // Fragment - less than one complete block of data _inode.StartBlock = 0xFFFFFFFF; _inode.FragmentKey = context.WriteFragment(bufferedBytes, out _inode.FragmentOffset); _inode.FileSize = (uint)bufferedBytes; } else { // At least one full block, no fragments used _inode.FragmentKey = 0xFFFFFFFF; _lengths = new List<uint>(); _inode.StartBlock = (uint)startPos; _inode.FileSize = bufferedBytes; while (bufferedBytes > 0) { _lengths.Add(context.WriteDataBlock(context.IoBuffer, 0, bufferedBytes)); bufferedBytes = Utilities.ReadFully(_source, context.IoBuffer, 0, context.DataBlockSize); _inode.FileSize += (uint)bufferedBytes; } } } finally { if (disposeSource) { _source.Dispose(); } } }