You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The File class has all methods for bytes which also exist for text except of appending data. Not only that it fits into the api surface by filling this gap is also saves us writing more than one line of code.
API Proposal
namespace System.IO;
public class File
{
+ public static void AppendAllBytes(string path, ReadOnlySpan<byte> data);+ public static Task AppendAllBytesAsync(string path, ReadOnlyMemory<byte> data, CancellationToken cancellationToken = default);
public static void AppendAllText(string path, string? contents);
public static Task AppendAllTextAsync(string path, string? contents, CancellationToken cancellationToken = default);
}
Why the API should allow for nulls? What is the point of appending nothing to a file? Creating it? If so, we have dedicated API for that.
We need an async overload too.
The mentioned APIs were introduced before Span and Memory, the new methods should accepts ReadOnlySpan and ReadOnlyMemory to accept both arrays and other types of inputs.
namespace System.IO;
public class File
{
+ public static void AppendAllBytes(string path, ReadOnlySpan<byte> data);+ public static Task AppendAllBytesAsync(string path, ReadOnlyMemory<byte> data, CancellationToken cancellationToken = default);
}
Having said that, I am going to update the proposal and make it as ready for review.
Why the API should allow for nulls? What is the point of appending nothing to a file? Creating it? If so, we have dedicated API for that.
There's value in being consistent with the existing APIs here. If someone is using WriteAllText with something that ends up being null and they decide to switch to appending rather than overriding, it'd be nice if that didn't then entail having to handle the arguments differently.
The mentioned APIs were introduced before Span and Memory, the new methods should accepts ReadOnlySpan and ReadOnlyMemory to accept both arrays and other types of inputs.
Do we want ReadOnly{Span/Memory}<byte> overloads then for the existing ones? What about ReadOnlySpan<char> for the ones currently only accepting strings?
@AlexRadch please excuse me, for some reason I've missed the notification. Since you still have some actionable PRs opened (example: #88009 (review)), I am going to assign @MojtabaTajik. I hope you don't mind.
Activity
gfoidl commentedon Apr 11, 2023
The
dataargument should be of typeReadOnlySpan<byte>instead ofbyte[]??Symbai commentedon Apr 11, 2023
WriteAllBytesuses byte[] instead of span, thats why I used it here as well but yeah sure it can be a span.adamsitnik commentedon May 19, 2023
Few comments from my side:
nulls? What is the point of appending nothing to a file? Creating it? If so, we have dedicated API for that.SpanandMemory, the new methods should acceptsReadOnlySpanandReadOnlyMemoryto accept both arrays and other types of inputs.namespace System.IO; public class File { + public static void AppendAllBytes(string path, ReadOnlySpan<byte> data); + public static Task AppendAllBytesAsync(string path, ReadOnlyMemory<byte> data, CancellationToken cancellationToken = default); }Having said that, I am going to update the proposal and make it as ready for review.
Symbai commentedon May 19, 2023
The AppendAllText allows a nullable string I only followed this choice.
runtime/src/libraries/System.Private.CoreLib/src/System/IO/File.cs
Lines 775 to 776 in 4c75b58
Possibly because of that:
runtime/src/libraries/System.Private.CoreLib/src/System/IO/File.cs
Lines 1211 to 1222 in 4c75b58
stephentoub commentedon May 19, 2023
There's value in being consistent with the existing APIs here. If someone is using WriteAllText with something that ends up being null and they decide to switch to appending rather than overriding, it'd be nice if that didn't then entail having to handle the arguments differently.
Do we want
ReadOnly{Span/Memory}<byte>overloads then for the existing ones? What aboutReadOnlySpan<char>for the ones currently only accepting strings?9 remaining items
MojtabaTajik commentedon Jul 31, 2023
@adamsitnik @stephentoub Can I work on this API implementation?
adamsitnik commentedon Jul 31, 2023
@AlexRadch please excuse me, for some reason I've missed the notification. Since you still have some actionable PRs opened (example: #88009 (review)), I am going to assign @MojtabaTajik. I hope you don't mind.
adamsitnik commentedon Jul 31, 2023
@MojtabaTajik I've assigned you, please let me know if you need some help.
tcortega commentedon Sep 30, 2023
Hi @adamsitnik and @MojtabaTajik,
I noticed this PR has been quiet since August 19th. If it's okay, I'd like to help out or take it on.
MojtabaTajik commentedon Sep 30, 2023
Hey @tcortega
I was on vacation, but I hope to get it done this week.