FluentFTP
FluentFTP copied to clipboard
Override Read(Span), ReadAsync(Memory), Write(ROS), WriteAsync(ROM) in streams
Available in NETSTANDARD2_1 and NET5_0_OR_GREATER, the base class functions in Stream for backwards compatibility rent an array and copy the span to it and then call the old array based functions.
As an optimization FtpDataStream and FtpSocketStream can override these functions and pass the call directly onto the wrapped stream.
Closes #1570
The changes look good. But are these new methods automatically used by the .NET Framework or the Stream system? As we are not invoking it directly.
@robinrodricks Yes stream and other places in system will now prefer to use the new overloads if they don't already have an array. For example FileStream.CopyToAsync uses the memory overload https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.Windows.cs#L299C39-L299C49
So they may already be getting called. Will know if we can put a break point in there when the tests are run. Otherwise we will need to add more.
I have also been investigating bypassing the BUF copying inherent in the FtpDataStream and FtpSocketStream on the way to (or from) network stream.
Newer .NET versions give one this option:
Prefer the memory-based overloads of ReadAsync/WriteAsync methods in stream-based classes
For example: await base.ReadAsync(buffer.AsMemory(offset, count), token);
instead of await base.ReadAsync(buffer, offset, count, token);
Would of course be a code change and another set of #IF/#ENDIF brackets.
Added 2 more UploadDownload tests as the existing ones weren't using the streams directly. Fixed a couple of compiler warnings in the file also.
This looks interesting. I'm merging it for now. If we have serious issues arising from this change, we can revert it.
Thanks for your contribution!