Skip to content

Commit

Permalink
DecodedToStream to DecodeToStream (#17140)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Sébastien Ros <[email protected]>
  • Loading branch information
MikeAlhayek and sebastienros authored Dec 6, 2024
1 parent 9f8423a commit ce0850f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected override async Task HandleAsync(RecipeExecutionContext context)
{
if (!string.IsNullOrWhiteSpace(file.Base64))
{
stream = Base64.DecodedToStream(file.Base64);
stream = Base64.DecodeToStream(file.Base64);
}
else if (!string.IsNullOrWhiteSpace(file.SourcePath))
{
Expand Down
10 changes: 7 additions & 3 deletions src/OrchardCore/OrchardCore.Abstractions/Base64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ public static string FromUTF8Base64String(string base64)
return Encoding.UTF8.GetString(span.Slice(0, bytesWritten));
}

[Obsolete("This will be deprecated in v4. Please use DecodeToStream instead.")]
public static Stream DecodedToStream(string base64)
=> DecodeToStream(base64);

/// <summary>
/// Converts a base64 encoded string to a stream.
/// </summary>
/// <param name="base64">The base64 encoded string.</param>
/// <remarks>The resulting <see cref="Stream"/> should be disposed once used.</remarks>
/// <remarks>The resulting <see cref="Stream"/> is positioned at index 0 and should be disposed once used.</remarks>
/// <returns>The decoded stream.</returns>
/// <exception cref="FormatException"></exception>
public static Stream DecodedToStream(string base64)
public static Stream DecodeToStream(string base64)
{
ArgumentNullException.ThrowIfNull(base64);

Expand All @@ -52,7 +56,7 @@ public static Stream DecodedToStream(string base64)

memoryStream.Advance(bytesWritten);
memoryStream.Seek(0, SeekOrigin.Begin);

return memoryStream;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static CommonGeneratorMethods()
Name = "gzip",
Method = serviceProvider => (Func<string, string>)(encoded =>
{
var compressedStream = Base64.DecodedToStream(encoded);
var compressedStream = Base64.DecodeToStream(encoded);

using var gZip = new GZipStream(compressedStream, CompressionMode.Decompress, leaveOpen: true);

Expand Down
2 changes: 1 addition & 1 deletion test/OrchardCore.Tests/Abstractions/Base64Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void DecodeToStringTest(string source, string expected)
[InlineData("", "")]
public void DecodeToStreamTest(string source, string expected)
{
using var stream = Base64.DecodedToStream(source);
using var stream = Base64.DecodeToStream(source);
using var sr = new StreamReader(stream);
{
Assert.Equal(expected, sr.ReadToEnd());
Expand Down

0 comments on commit ce0850f

Please sign in to comment.