Class StreamExtensions
- Namespace
- Tripous
- Assembly
- Tripous.dll
Extensions
public static class StreamExtensions
- Inheritance
-
StreamExtensions
- Inherited Members
Methods
AddPreambleTo(byte[], Encoding)
Adds the preamble of the Encoding in front of the Buffer
public static byte[] AddPreambleTo(byte[] Buffer, Encoding Encoding)
Parameters
Returns
- byte[]
BytesOf(string, Encoding, Encoding, bool)
Encodes Text into a byte array. Text must be in SourceEncoding.
If SourceEncoding is null then Encoding.UTF8 is assumed.
If DestEncoding is not null then the result byte array is converted to that Encoding.
If PutPreamble is true then a preamble is put in front of the result array
public static byte[] BytesOf(string Text, Encoding SourceEncoding = null, Encoding DestEncoding = null, bool PutPreamble = false)
Parameters
Returns
- byte[]
CopyAllTo(Stream, Stream, int)
Copies all bytes from the beginning of Source to the current Dest position. Requires a seekable Source and does not reset Dest after the copy operation is complete.
public static void CopyAllTo(this Stream Source, Stream Dest, int BufferSize = 1048576)
Parameters
FindEncoding(byte[])
Returns the Encoding if a Preamble exists in a text buffer, if any, else Encoding.Default.
public static Encoding FindEncoding(byte[] Buffer)
Parameters
Bufferbyte[]
Returns
GetEncoding(byte[])
Returns the Encoding if a Preamble exists in a text buffer, if any, else null.
public static Encoding GetEncoding(byte[] Buffer)
Parameters
Bufferbyte[]
Returns
RemovePreambleFrom(byte[])
Removes any preamble in front of the Buffer
public static byte[] RemovePreambleFrom(byte[] Buffer)
Parameters
Bufferbyte[]
Returns
- byte[]
StringOf(byte[], Encoding, Encoding)
Decodes Buffer into a string. Buffer must be in SourceEncoding.
If SourceEncoding is null then a preamble is used, if any, else Encoding.UTF8 is assumed.
If DestEncoding is not null then Buffer is first converted to that Encoding
public static string StringOf(byte[] Buffer, Encoding SourceEncoding = null, Encoding DestEncoding = null)
Parameters
Returns
ToArray(Stream)
Writes the stream contents to a byte array, regardless of the Stream Position. Restores the Stream Position when the stream is seekable.
public static byte[] ToArray(this Stream Stream)
Parameters
StreamStream
Returns
- byte[]