public override int Read(byte[] buffer, long offset, int count) { int result = 0; try { //if (offset == 5046272) //{ // Array.Copy(testBytes, buffer, count); //} int firstIndex = Search(offset); int i = firstIndex; int bufferOffset = 0; int bufferRemaining = buffer.Length; do { FileInfo fileInfo = _fileInfoArray[i]; long fsOffset = i == firstIndex ? offset - fileInfo.Begin : 0; int fsCount = Math.Min((int)(fileInfo.Length - fsOffset), bufferRemaining); string path = fileInfo.Path; FileStream fs = _fileStreamDict[path]; lock (fs) { fs.Seek(fsOffset, SeekOrigin.Begin); int readCount = fs.Read(buffer, bufferOffset, fsCount); Debug.Assert(readCount == fsCount); //for (int j = 0; j < fsCount; j++) //{ // if (offset == 73 * 65536 && j + bufferOffset >= 8269 + 16384 * 3 && j + bufferOffset < 8271+ 16384 * 3) // { // Console.WriteLine("{0}: {1}, {2}", _fileRanges[i].Path, j, buffer[bufferOffset + j]); // } //} //fs.Flush(); } i++; bufferOffset += fsCount; bufferRemaining -= fsCount; } while (bufferRemaining != 0); //lock (_fileStream) //{ // _fileStream.Seek(offset, SeekOrigin.Begin); // result = _fileStream.Read(buffer, 0, count); //} } catch (ObjectDisposedException) { //Nothing to be done. } return(result); }
public override void Write(byte[] buffer, long offset) { try { //Array.Copy(buffer, 0, Buffer, offset, buffer.Length); int firstIndex = Search(offset); int i = firstIndex; int bufferOffset = 0; int bufferRemaining = buffer.Length; do { FileInfo fileInfo = _fileInfoArray[i]; long fsOffset = i == firstIndex ? offset - fileInfo.Begin : 0; int fsCount = Math.Min((int)(fileInfo.Length - fsOffset), bufferRemaining); string path = fileInfo.Path; FileStream fs = _fileStreamDict[path]; lock (fs) { fs.Seek(fsOffset, SeekOrigin.Begin); fs.Write(buffer, bufferOffset, fsCount); fs.Flush(); //byte[] validBuffer = new byte[fsCount]; //fs.Seek(fsOffset, SeekOrigin.Begin); //fs.Read(validBuffer, 0, fsCount); //for (int j = 0; j < fsCount; j++) //{ // if (offset == 73 * 65536 + 16384 * 3 && j + bufferOffset >= 8269 && j + bufferOffset < 8271) // { // Console.WriteLine("Write: {0}: {1}, {2}, {3}", _fileRanges[i].Path, j, buffer[bufferOffset + j], validBuffer[j]); // } // int x = 0; // if (buffer[bufferOffset + j] != validBuffer[j]) // { // x++; // } //} } i++; bufferOffset += fsCount; bufferRemaining -= fsCount; } while (bufferRemaining != 0); } catch (ObjectDisposedException) { //Nothing to be done. } //byte[] readBuffer = new byte[buffer.Length]; //Read(readBuffer, offset, buffer.Length); //for (int i = 0; i < buffer.Length; i++) //{ // if (readBuffer[i] != buffer[i]) // { // Console.WriteLine("{0}: {1}, {2}", i, readBuffer[i], buffer[i]); // } //} }