Jackett/src/Jackett.Common/Utils/DataUrl.cs

28 lines
736 B
C#
Raw Normal View History

2015-04-13 14:25:41 +00:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2015-04-14 14:51:56 +00:00
using System.Web;
using MimeMapping;
2015-04-13 14:25:41 +00:00
2015-07-19 17:18:54 +00:00
namespace Jackett.Utils
2015-04-13 14:25:41 +00:00
{
2015-07-19 17:18:54 +00:00
public class DataUrlUtils
2015-04-13 14:25:41 +00:00
{
public static string ReadFileToDataUrl(string file)
{
string mime = MimeUtility.GetMimeMapping(file);
2015-04-13 14:25:41 +00:00
return "data:" + mime + ";base64," + Convert.ToBase64String(File.ReadAllBytes(file));
}
public static string BytesToDataUrl(byte[] bytes, string mimeType = "image/jpg")
{
2017-01-05 16:31:52 +00:00
if (bytes == null)
return null;
2015-04-13 14:25:41 +00:00
return "data:" + mimeType + ";base64," + Convert.ToBase64String(bytes);
}
}
}