using System;
using System.IO;
using System.Text;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
///
/// Provides helper overloads to a .
///
public static class BlobExtensions
{
///
/// Gets the blob content decoded with the specified encoding,
/// or according to byte order marks, with UTF8 as fallback,
/// if is null.
///
/// The blob for which the content will be returned.
/// The encoding of the text. (default: detected or UTF8)
/// Blob content as text.
public static string GetContentText(this Blob blob, Encoding encoding = null)
{
Ensure.ArgumentNotNull(blob, "blob");
using (var reader = new StreamReader(blob.GetContentStream(), encoding ?? Encoding.UTF8, encoding == null))
{
return reader.ReadToEnd();
}
}
///
/// Gets the blob content as it would be checked out to the
/// working directory, decoded with the specified encoding,
/// or according to byte order marks, with UTF8 as fallback,
/// if is null.
///
/// The blob for which the content will be returned.
/// Parameter controlling content filtering behavior
/// The encoding of the text. (default: detected or UTF8)
/// Blob content as text.
public static string GetContentText(this Blob blob, FilteringOptions filteringOptions, Encoding encoding = null)
{
Ensure.ArgumentNotNull(blob, "blob");
Ensure.ArgumentNotNull(filteringOptions, "filteringOptions");
using (var reader = new StreamReader(blob.GetContentStream(filteringOptions), encoding ?? Encoding.UTF8, encoding == null))
{
return reader.ReadToEnd();
}
}
}
}