mime.zip
MIME
App.ico
bin
Debug
00.jpg
MIME.csproj.user
MIME.suo
|
using System;
using System.IO;
using System.Text;
namespace MIME
{
/// <summary>
///
/// </summary>
public class MimeCodeBase64 : MIME.MimeCode
{
public MimeCodeBase64()
{
//
// TODO: Add constructor logic here
//
}
public override byte[] DecodeToBytes(string s)
{
if(s == null)
throw new ArgumentNullException();
return System.Convert.FromBase64String(s);
}
public override string EncodeFromBytes(byte[] inArray, int offset, int length)
{
if(inArray == null)
throw new ArgumentNullException();
return FormatEncodedString(System.Convert.ToBase64String(inArray, offset, length));
}
string FormatEncodedString(string s)
{
if(s == null)
throw new ArgumentNullException();
const int MAX_CHAR_LEN = 76;
int index = 0;
StringBuilder sb = new StringBuilder();
while((index+MAX_CHAR_LEN) < s.Length)
{
sb.AppendFormat("{0}\r\n", s.Substring(index, MAX_CHAR_LEN));
index += MAX_CHAR_LEN;
}
sb.AppendFormat("{0}", s.Substring(index, s.Length - index));
return sb.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.