4using System.Threading.Tasks;
82 else if (ContentType.StartsWith(
"text/"))
104 public Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding,
105 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
118 switch (FileExtension.ToLower())
137 ContentType =
"text/sgml";
141 ContentType =
"text/richtext";
145 ContentType =
string.Empty;
158 switch (ContentType.ToLower())
161 FileExtension =
"txt";
165 FileExtension =
"sgml";
168 case "text/richtext":
169 FileExtension =
"rtx";
173 FileExtension =
string.Empty;
187 if (Object is
string)
196 foreach (
string s
in AcceptedContentTypes)
198 if (s.StartsWith(
"text/"))
219 public Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
224 if (Encoding is
null)
227 Encoding = Encoding.UTF8;
232 return Task.FromResult(
new ContentResponse(ContentType, Object, Encoding.GetBytes(Object.ToString())));
Contains information about a response to a content request.
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Plain text encoder/decoder.
Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
const string DefaultContentType
text/plain
static readonly string[] PlainTextContentTypes
Plain text content types.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
string[] ContentTypes
Supported content types.
static readonly string[] PlainTextFileExtensions
Plain text file extensions.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
string[] FileExtensions
Supported file extensions.
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
PlainTextCodec()
Plain text encoder/decoder.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
Static class managing binary representations of strings.
static string GetString(byte[] Data, int Offset, int Count, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...