8000 Use LaxUtf8Marshaler when returning the blob as a string · GiTechLab/libgit2sharp@c91fb85 · GitHub
[go: up one dir, main page]

Skip to content

Commit c91fb85

Browse files
committed
Use LaxUtf8Marshaler when returning the blob as a string
1 parent 41a1bae commit c91fb85

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

LibGit2Sharp/BlobExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static string GetContentText(this Blob blob, Encoding encoding = null)
2222
{
2323
Ensure.ArgumentNotNull(blob, "blob");
2424

25-
return ReadToEnd(blob.GetContentStream, encoding);
25+
return ReadToEnd(blob.GetContentStream(), encoding);
2626
}
2727

2828
/// <summary>
@@ -40,12 +40,12 @@ public static string GetContentText(this Blob blob, FilteringOptions filteringOp
4040
Ensure.ArgumentNotNull(blob, "blob");
4141
Ensure.ArgumentNotNull(filteringOptions, "filteringOptions");
4242

43-
return ReadToEnd(() => blob.GetContentStream(filteringOptions), encoding);
43+
return ReadToEnd(blob.GetContentStream(filteringOptions), encoding);
4444
}
4545

46-
private static string ReadToEnd(Func<Stream> streamProvider, Encoding encoding)
46+
private static string ReadToEnd(Stream stream, Encoding encoding)
4747
{
48-
using (var reader = new StreamReader(streamProvider(), encoding ?? Encoding.UTF8, encoding == null))
48+
using (var reader = new StreamReader(stream, encoding ?? LaxUtf8Marshaler.Encoding, encoding == null))
4949
{
5050
return reader.ReadToEnd();
5151
}

LibGit2Sharp/Core/Utf8Marshaler.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ internal class LaxUtf8Marshaler : EncodingMarshaler
9191
{
9292
private static readonly LaxUtf8Marshaler staticInstance = new LaxUtf8Marshaler();
9393

94-
private static readonly Encoding encoding = new UTF8Encoding(false, false);
94+
public static readonly Encoding Encoding = new UTF8Encoding(false, false);
9595

96-
public LaxUtf8Marshaler() : base(encoding)
96+
public LaxUtf8Marshaler() : base(Encoding)
9797
{ }
9898

9999
public static ICustomMarshaler GetInstance(String cookie)
@@ -113,22 +113,22 @@ public override IntPtr MarshalManagedToNative(object managedObj)
113113

114114
public static string FromNative(IntPtr pNativeData)
115115
{
116-
return FromNative(encoding, pNativeData);
116+
return FromNative(Encoding, pNativeData);
117117
}
118118

119119
public static string FromNative(IntPtr pNativeData, int length)
120120
{
121-
return FromNative(encoding, pNativeData, length);
121+
return FromNative(Encoding, pNativeData, length);
122122
}
123123

124124
public static string FromBuffer(byte[] buffer)
125125
{
126-
return FromBuffer(encoding, buffer);
126+
return FromBuffer(Encoding, buffer);
127127
}
128128

129129
public static string FromBuffer(byte[] buffer, int length)
130130
{
131-
return FromBuffer(encoding, buffer, length);
131+
return FromBuffer(Encoding, buffer, length);
132132
}
133133
}
134134
}

0 commit comments

Comments
 (0)
0