/// <inheritdoc/> public async Task ReadAsync(Stream output, long offset, long length, ITransferDataOperationContext operationContext, ITransferDataResultContext resultContext) { Logger.LogMessage($"{nameof(IFile)}.{nameof(ReadAsync)}({offset}, {length})", UserFileSystemPath); SimulateNetworkDelay(length, resultContext); await using (FileStream stream = System.IO.File.OpenRead(RemoteStoragePath)) { stream.Seek(offset, SeekOrigin.Begin); const int bufferSize = 0x500000; // 5Mb. Buffer size must be multiple of 4096 bytes for optimal performance. await stream.CopyToAsync(output, bufferSize, length); } }
//$> //$<IFile.TransferDataAsync /// <inheritdoc/> public async Task TransferDataAsync(long offset, long length, ITransferDataOperationContext operationContext, ITransferDataResultContext resultContext) { // This method has a 60 sec timeout. // To process longer requests and reset the timout timer call resultContext.ReportProgress() method. Logger.LogMessage($"IFile.TransferDataAsync({offset}, {length})", UserFileSystemPath); SimulateNetworkDelay(length, resultContext); long optionalLength = length + operationContext.OptionalLength; byte[] buffer = await new UserFile(UserFileSystemPath).ReadAsync(offset, optionalLength); resultContext.ReturnData(buffer, offset, optionalLength); }
public async Task TransferDataAsync(long offset, long length, ITransferDataOperationContext operationContext, ITransferDataResultContext resultContext) { Logger.LogMessage($"IFile.TransferDataAsync({offset}, {length})", UserFileSystemPath); byte[] buffer = new byte[length]; await using (FileStream stream = File.OpenRead(RemoteStoragePath)) { stream.Seek(offset, SeekOrigin.Begin); int bytesRead = await stream.ReadAsync(buffer, 0, (int)length); } resultContext.ReturnData(buffer, offset, length); }
/// <inheritdoc/> public async Task ReadAsync(Stream output, long offset, long length, ITransferDataOperationContext operationContext, ITransferDataResultContext resultContext) { // On Windows this method has a 60 sec timeout. // To process longer requests and reset the timout timer call the resultContext.ReportProgress() or resultContext.ReturnData() method. Logger.LogMessage($"{nameof(IFile)}.{nameof(ReadAsync)}({offset}, {length})", UserFileSystemPath); SimulateNetworkDelay(length, resultContext); await using (FileStream stream = System.IO.File.OpenRead(RemoteStoragePath)) { stream.Seek(offset, SeekOrigin.Begin); const int bufferSize = 0x500000; // 5Mb. Buffer size must be multiple of 4096 bytes for optimal performance. await stream.CopyToAsync(output, bufferSize, length); } }
/// <inheritdoc/> public async Task TransferDataAsync(long offset, long length, ITransferDataOperationContext operationContext, ITransferDataResultContext resultContext) { // On Windows this method has a 60 sec timeout. // To process longer requests and reset the timout timer call the resultContext.ReportProgress() or resultContext.ReturnData() method. // For files > 4Gb we have to use the OptionalLength. if (operationContext.FileSize > 0x100000000) { length += operationContext.OptionalLength; } Logger.LogMessage($"{nameof(IFile)}.{nameof(TransferDataAsync)}({offset}, {length})", UserFileSystemPath); SimulateNetworkDelay(length, resultContext); IVirtualFile userFile = await VirtualDrive.GetItemAsync <IVirtualFile>(UserFileSystemPath, Logger); await userFile.ReadAsync(offset, length, operationContext.FileSize, resultContext); }
/// <inheritdoc/> public async Task TransferDataAsync(long offset, long length, ITransferDataOperationContext operationContext, ITransferDataResultContext resultContext) { // This method has a 60 sec timeout. // To process longer requests and reset the timout timer call IContextWindows.ReportProgress() method. LogMessage($"IFile.TransferDataAsync({offset}, {length})", this.FullPath); SimulateNetworkDelay(length, resultContext); string remoteStoragePath = Mapping.MapPath(this.FullPath); // Transfering file content. await using (FileStream stream = File.OpenRead(remoteStoragePath)) { stream.Seek(offset, SeekOrigin.Begin); byte[] buffer = new byte[length]; int bytesRead = await stream.ReadAsync(buffer, 0, (int)length); resultContext.ReturnData(buffer, offset, length); } }
public async Task TransferDataAsync(long offset, long length, ITransferDataOperationContext operationContext, ITransferDataResultContext resultContext) { throw new NotImplementedException(); }