Esempio n. 1
0
        private void CreateWriterWorkItemForNewChunk(ChunkHeader chunkHeader)
        {
            var md5    = MD5.Create();
            var stream = new FileStream(_filename, FileMode.Create, FileAccess.ReadWrite, FileShare.Read,
                                        WriteBufferSize, FileOptions.SequentialScan);
            var writer = new BinaryWriter(stream);

            stream.SetLength(chunkHeader.ChunkSize + ChunkHeader.Size + ChunkFooter.Size);
            WriteHeader(md5, stream, chunkHeader);
            _writerWorkItem = new WriterWorkItem(stream, writer, md5);
            Flush();
        }
Esempio n. 2
0
        private void CloseWriterStream()
        {
            if (_writerWorkItem == null)
            {
                return;
            }

            if (_writerWorkItem.Stream != null)
            {
                _writerWorkItem.Stream.Dispose();
            }

            var unmanagedStream = _writerWorkItem.UnmanagedMemoryStream;

            if (unmanagedStream != null)
            {
                unmanagedStream.Dispose();
                _writerWorkItem.UnmanagedMemoryStream = null;
            }
            _writerWorkItem = null;
        }
Esempio n. 3
0
        private void CreateWriterWorkItemForExistingChunk(int writePosition, out ChunkHeader chunkHeader)
        {
            var md5    = MD5.Create();
            var stream = new FileStream(_filename, FileMode.Open, FileAccess.ReadWrite, FileShare.Read,
                                        WriteBufferSize, FileOptions.SequentialScan);
            var writer = new BinaryWriter(stream);

            try
            {
                chunkHeader = ReadHeader(stream);
            }
            catch
            {
                stream.Dispose();
                ((IDisposable)md5).Dispose();
                throw;
            }
            var realPosition = GetRealPosition(writePosition, inMemory: false);

            stream.Position = realPosition;
            MD5Hash.ContinuousHashFor(md5, stream, 0, realPosition);
            _writerWorkItem = new WriterWorkItem(stream, writer, md5);
        }
Esempio n. 4
0
 private void CreateWriterWorkItemForNewChunk(ChunkHeader chunkHeader)
 {
     var md5 = MD5.Create();
     var stream = new FileStream(_filename, FileMode.Create, FileAccess.ReadWrite, FileShare.Read,
                                 WriteBufferSize, FileOptions.SequentialScan);
     var writer = new BinaryWriter(stream);
     stream.SetLength(chunkHeader.ChunkSize + ChunkHeader.Size + ChunkFooter.Size);
     WriteHeader(md5, stream, chunkHeader);
     _writerWorkItem = new WriterWorkItem(stream, writer, md5);
     Flush();
 }
Esempio n. 5
0
 private void CreateWriterWorkItemForExistingChunk(int writePosition, out ChunkHeader chunkHeader)
 {
     var md5 = MD5.Create();
     var stream = new FileStream(_filename, FileMode.Open, FileAccess.ReadWrite, FileShare.Read,
                                 WriteBufferSize, FileOptions.SequentialScan);
     var writer = new BinaryWriter(stream);
     try
     {
         chunkHeader = ReadHeader(stream);
     }
     catch
     {
         stream.Dispose();
         ((IDisposable)md5).Dispose();
         throw;
     }
     var realPosition = GetRealPosition(writePosition, inMemory: false);
     stream.Position = realPosition;
     MD5Hash.ContinuousHashFor(md5, stream, 0, realPosition);
     _writerWorkItem = new WriterWorkItem(stream, writer, md5);
 }
Esempio n. 6
0
        private void CloseWriterStream()
        {
            if (_writerWorkItem == null)
                return;

            if (_writerWorkItem.Stream != null)
                _writerWorkItem.Stream.Dispose();

            var unmanagedStream = _writerWorkItem.UnmanagedMemoryStream;
            if (unmanagedStream != null)
            {
                unmanagedStream.Dispose();
                _writerWorkItem.UnmanagedMemoryStream = null;
            }
            _writerWorkItem = null;
        }
Esempio n. 7
0
 private static int GetLogicalPosition(WriterWorkItem workItem)
 {
     return (int) workItem.Stream.Position - ChunkHeader.Size;
 }
Esempio n. 8
0
 private static int GetLogicalPosition(WriterWorkItem workItem)
 {
     return((int)workItem.Stream.Position - ChunkHeader.Size);
 }