Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DecodedToStream to DecodeToStream #17140

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 6 additions & 2 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 DecodedToStream1(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>
/// <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,8 @@ static CommonGeneratorMethods()
Name = "gzip",
Method = serviceProvider => (Func<string, string>)(encoded =>
{
var compressedStream = Base64.DecodedToStream(encoded);
var compressedStream = Base64.DecodeToStream(encoded);
compressedStream.Seek(0, SeekOrigin.Begin);

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
Loading