public void Cut(string mFilePath, List <FilePiece> mQueeue) { using (var reader = new BinaryReader(new FileStream(mFilePath, FileMode.Open, FileAccess.Read))) { int counter = 0; var BUFFER_SIZE = AppPropertiesSingle.GetInstance().m_BufferSize; long oldPs = 0; while (reader.BaseStream.Position < reader.BaseStream.Length) { reader.BaseStream.Seek(counter * BUFFER_SIZE, SeekOrigin.Begin); var bufferSize = BUFFER_SIZE; if (reader.BaseStream.Length - reader.BaseStream.Position <= BUFFER_SIZE) { bufferSize = (int)(reader.BaseStream.Length - reader.BaseStream.Position); } var arBytes = reader.ReadBytes(bufferSize); var compressedBytes = ProcessPacking.ProcessArchive(arBytes); mQueeue.Add(new FilePiece(counter, compressedBytes)); counter++; long ps = reader.BaseStream.Position * 100 / reader.BaseStream.Length; if (ps != oldPs) { NotifyProgress?.Invoke(ps.ToString()); } oldPs = ps; } } }
private void CutPath(object o) { // индекс потока int index = (int)o; // файл, чтобы складывать все с потока var filePath = AppPropertiesSingle.GetInstance().TempPath; var tempFileName = index + Path.GetRandomFileName(); filePath = Path.Combine(filePath, tempFileName); // позиция курсора и конец отрезка в зависимости от идекса потока long cursorPos = m_StreamLength * index; long endPos = cursorPos + m_StreamLength; using (var reader = new BinaryReader(new FileStream(m_FilePath, FileMode.Open, FileAccess.Read))) { long BUFFER_SIZE = (long)AppPropertiesSingle.GetInstance().m_BufferSize; // для расчета прогресса long counter = 0; long oldPs = 0; // создаем файлик для записи using (var bw = new BinaryWriter(new FileStream(filePath, FileMode.Create))) { while (reader.BaseStream.Position < reader.BaseStream.Length) { long offset = cursorPos + counter * BUFFER_SIZE; var ps = (offset - cursorPos) * 100 / (endPos - cursorPos); if (ps != oldPs) { m_ProgressList[index] = ps; } if (offset > endPos) { break; } reader.BaseStream.Seek(offset, SeekOrigin.Begin); var bufferSize = BUFFER_SIZE; var nextoffset = cursorPos + (counter + 1) * BUFFER_SIZE; if (nextoffset > endPos) { bufferSize = (int)(endPos - offset); } var arBytes = reader.ReadBytes((int)bufferSize); // заархивируем считанный кусочек var compBytes = ProcessPacking.ProcessArchive(arBytes); bw.Write(compBytes); counter++; } } m_ThreadPieceList[index] = new FilePiece(filePath); } }