private void FileWriter(string path) { try { using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { fs.Position = sizeof(UInt64); while (true) { if (_token.IsCancellationRequested) { break; } if (_queue.Peek() == null) { break; } IChunk chunk = _queue.Dequeue(); fs.Write(chunk.Header, 0, chunk.Header.Length); fs.Write(chunk.Data, 0, chunk.Data.Length); chunk.Clear(); _count++; } fs.Position = 0; byte[] buffer = BitConverter.GetBytes(_count); fs.Write(buffer, 0, buffer.Length); } } catch (Exception exp) { _queue.Stop(true); Error = new Exception("Ошибка записи файла", exp); } finally { _queue.Stop(true); _endEvent.Set(); } }
private void FileWriter(string path) { try { using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { while (true) { if (_token.IsCancellationRequested) { break; } if (_queue.Peek() == null) { break; } if (fs.Position != _queue.Peek().Position&& _queue.Count != _queue.Size) { continue; } IChunk chunk = _queue.Dequeue(); fs.Position = chunk.Position; fs.Write(chunk.Data, 0, chunk.Data.Length); chunk.Clear(); } } } catch (Exception exp) { _queue.Stop(true); Error = new Exception("Ошибка записи файла", exp); } finally { _queue.Stop(true); _endEvent.Set(); } }
public IChunk Read() { return(_queue.Dequeue()); }