Skip to content

Commit 9fffc4f

Browse files
haackednulltoken
authored andcommitted
Add BlobExtensions
1 parent d9f60de commit 9fffc4f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

LibGit2Sharp/BlobExtensions.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Text;
2+
3+
namespace LibGit2Sharp
4+
{
5+
/// <summary>
6+
/// Provides helper overloads to a <see cref = "Blob" />.
7+
/// </summary>
8+
public static class BlobExtensions
9+
{
10+
/// <summary>
11+
/// Gets the blob content decoded as UTF-8.
12+
/// </summary>
13+
/// <param name="blob">The blob for which the content will be returned.</param>
14+
/// <returns>Blob content as UTF-8</returns>
15+
public static string ContentAsUtf8(this Blob blob)
16+
{
17+
return Encoding.UTF8.GetString(blob.Content);
18+
}
19+
20+
/// <summary>
21+
/// Gets the blob content decoded as Unicode.
22+
/// </summary>
23+
/// <param name="blob">The blob for which the content will be returned.</param>
24+
/// <returns>Blob content as unicode.</returns>
25+
public static string ContentAsUnicode(this Blob blob)
26+
{
27+
return Encoding.Unicode.GetString(blob.Content);
28+
}
29+
}
30+
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<ItemGroup>
5858
<Compile Include="AbbreviatedObjectId.cs" />
5959
<Compile Include="Blob.cs" />
60+
<Compile Include="BlobExtensions.cs" />
6061
<Compile Include="Branch.cs" />
6162
<Compile Include="BranchCollection.cs" />
6263
<Compile Include="Changes.cs" />

0 commit comments

Comments
 (0)