DokanError IDokanOperations.ReadFile(string fileName, byte[] buffer, out int bytesRead, long offset, DokanFileInfo info) { Log("ReadFile:{0}:{1}|lenght:[{2}]|offset:[{3}]", fileName, info.Context, buffer.Length, offset); if (info.Context == null) { //called when file is read as memory memory mapeded file usualy notepad and stuff var handle = _sftpSession.RequestOpen(GetUnixPath(fileName), Flags.Read); var data = _sftpSession.RequestRead(handle, (ulong)offset, (uint)buffer.Length); _sftpSession.RequestClose(handle); Buffer.BlockCopy(data, 0, buffer, 0, data.Length); bytesRead = data.Length; } else { // var watch = Stopwatch.StartNew(); var stream = (info.Context as SftpContext).Stream; lock (stream) { stream.Position = offset; bytesRead = stream.Read(buffer, 0, buffer.Length); } // watch.Stop(); // Log("{0}",watch.ElapsedMilliseconds); } Log("END READ:{0},{1}", offset, info.Context); return(DokanError.ErrorSuccess); }
public override int Read(byte[] buffer, int offset, int count) { int readLen = 0; // Lock down the file stream while we do this. // Set up for the read operation. SetupRead(); // Read data into the caller's buffer. while (count > 0) { // How much data do we have available in the buffer? int tempLen = _readBuffer.Length - _readBufferPosition; if (tempLen <= 0) { _readBufferPosition = 0; _readBuffer = _session.RequestRead(_handle, (ulong)_position, READ_BUFFER_SIZE); if (_readBuffer.Length > 0) { tempLen = _readBuffer.Length; } else { break; } } // Don't read more than the caller wants. if (tempLen > count) { tempLen = count; } // Copy stream data to the caller's buffer. Debug.WriteLine("Copy:{0},{1},{2},{3},{4}", _readBuffer, _readBufferPosition, buffer, offset, tempLen); Buffer.BlockCopy(_readBuffer, _readBufferPosition, buffer, offset, tempLen); // Advance to the next buffer positions. readLen += tempLen; offset += tempLen; count -= tempLen; _readBufferPosition += tempLen; _position += tempLen; } // Return the number of bytes that were read to the caller. return(readLen); }
protected void Act() { _actual = _sftpSession.RequestRead(_handle, _offset, _length); }
protected void Act() { _actual = _sftpSession.RequestRead(new byte[0], 0, 200); }