PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.StreamExtensions Class Reference

Provides utility extensions on Stream objects. More...

Static Public Member Functions

static byte[] ReadAllBytes (this Stream src)
 Reads all bytes from a stream.
static async Task< byte[]> ReadAllBytesAsync (this Stream src)
 Reads all bytes from a stream.
static void WriteAllBytes (this Stream source, byte[] data)
 Writes all given bytes to a stream.
static async Task WriteAllBytesAsync (this Stream source, byte[] data)
 Writes all given bytes to a stream.
static void Rewind (this Stream src)
 Rewinds the current stream pointer to the beginning of the stream (when supported by the stream)
static void Append (this Stream target, byte[] data)
 Appends binary data to the end of the stream.
static async Task AppendAsync (this Stream target, byte[] data)
 Appends binary data to the end of the stream.
static string AsString (this Stream src, Encoding encoding=null)
 Attempts to get a string representation of the contents of a stream.
static async Task< string > AsStringAsync (this Stream src, Encoding encoding=null)
 Attempts to get a string representation of the contents of a stream.
static void WriteString (this Stream stream, string data)
 Invokes WriteString() with the UTF8 Encoding.
static async Task WriteStringAsync (this Stream stream, string data)
 Invokes WriteString() with the UTF8 Encoding.
static void WriteString (this Stream stream, string data, Encoding encoding)
 Writes a string to a stream with the provided encoding.
static async Task WriteStringAsync (this Stream stream, string data, Encoding encoding)
 Writes a string to a stream with the provided encoding.
static void Save (this Stream stream, string filePath)
 Saves a stream to a local file.
static async Task SaveAsync (this Stream stream, string filePath)
 Saves a stream to a local file.
static void AppendString (this Stream stream, string value)
 Appends a string to a stream.
static void AppendLine (this Stream stream, string line)
 Appends a text line to a stream.
static IEnumerable< string > ReadLines (this Stream stream)
 Reads the stream, line-for-line, with the UTF8 encoding.
static IEnumerable< string > ReadLines (this Stream stream, Action< Eol > onNewline)
 Reads the stream, line-for-line, with the UTF8 encoding. When a newline is encountered, the onNewLine func is called with the kind of line ending last encountered.
static IEnumerable< string > ReadLines (this Stream stream, Encoding encoding)
 Reads the stream, line-for-line, with the provided encoding.
static IEnumerable< string > ReadLines (this Stream stream, Encoding encoding, Action< Eol > onNewLine)
 Reads the stream, line-for-line, with the provided encoding. When a newline is encountered, the onNewLine func is called with the kind of line ending last encountered.
static string ReadLine (this Stream stream)
 Read one line from the stream, encoded as utf8.
static string ReadLine (this Stream stream, Encoding encoding)
 Read one line from the stream, with the provided encoding.
static string ReadAllText (this Stream stream)
 Read all content of a stream as text with utf8 encoding.
static string ReadAllText (this Stream stream, Encoding encoding)
 Read all content of a stream as text with the provided encoding.
static async Task< string > ReadAllTextAsync (this Stream stream)
 Read all content of a stream as text with utf8 encoding.
static async Task< string > ReadAllTextAsync (this Stream stream, Encoding encoding)
 Read all content of a stream as text with the provided encoding.

Detailed Description

Provides utility extensions on Stream objects.

Member Function Documentation

◆ Append()

void PeanutButter.Utils.StreamExtensions.Append ( this Stream target,
byte[] data )
static

Appends binary data to the end of the stream.

Parameters
targetTarget stream to write to
dataBinary data to write
Exceptions
IOExceptionThrown when the target stream is null

◆ AppendAsync()

async Task PeanutButter.Utils.StreamExtensions.AppendAsync ( this Stream target,
byte[] data )
static

Appends binary data to the end of the stream.

Parameters
targetTarget stream to write to
dataBinary data to write
Exceptions
IOExceptionThrown when the target stream is null

◆ AppendLine()

void PeanutButter.Utils.StreamExtensions.AppendLine ( this Stream stream,
string line )
static

Appends a text line to a stream.

Parameters
stream
line

◆ AppendString()

void PeanutButter.Utils.StreamExtensions.AppendString ( this Stream stream,
string value )
static

Appends a string to a stream.

Parameters
stream
value

◆ AsString()

string PeanutButter.Utils.StreamExtensions.AsString ( this Stream src,
Encoding encoding = null )
static

Attempts to get a string representation of the contents of a stream.

Parameters
srcSource stream to read
encodingOptional encoding to use (defaults to UTF8 when null)
Returns
A string representation of the stream

◆ AsStringAsync()

async Task< string > PeanutButter.Utils.StreamExtensions.AsStringAsync ( this Stream src,
Encoding encoding = null )
static

Attempts to get a string representation of the contents of a stream.

Parameters
srcSource stream to read
encodingOptional encoding to use (defaults to UTF8 when null)
Returns
A string representation of the stream

◆ ReadAllBytes()

byte[] PeanutButter.Utils.StreamExtensions.ReadAllBytes ( this Stream src)
static

Reads all bytes from a stream.

Parameters
srcSource stream to read from
Returns
Byte array of the data read from the stream

◆ ReadAllBytesAsync()

async Task< byte[]> PeanutButter.Utils.StreamExtensions.ReadAllBytesAsync ( this Stream src)
static

Reads all bytes from a stream.

Parameters
srcSource stream to read from
Returns
Byte array of the data read from the stream

◆ ReadAllText() [1/2]

string PeanutButter.Utils.StreamExtensions.ReadAllText ( this Stream stream)
static

Read all content of a stream as text with utf8 encoding.

Parameters
stream
Returns

◆ ReadAllText() [2/2]

string PeanutButter.Utils.StreamExtensions.ReadAllText ( this Stream stream,
Encoding encoding )
static

Read all content of a stream as text with the provided encoding.

Parameters
stream
encoding
Returns

◆ ReadAllTextAsync() [1/2]

async Task< string > PeanutButter.Utils.StreamExtensions.ReadAllTextAsync ( this Stream stream)
static

Read all content of a stream as text with utf8 encoding.

Parameters
stream
Returns

◆ ReadAllTextAsync() [2/2]

async Task< string > PeanutButter.Utils.StreamExtensions.ReadAllTextAsync ( this Stream stream,
Encoding encoding )
static

Read all content of a stream as text with the provided encoding.

Parameters
stream
encoding
Returns

◆ ReadLine() [1/2]

string PeanutButter.Utils.StreamExtensions.ReadLine ( this Stream stream)
static

Read one line from the stream, encoded as utf8.

Parameters
stream
Returns

◆ ReadLine() [2/2]

string PeanutButter.Utils.StreamExtensions.ReadLine ( this Stream stream,
Encoding encoding )
static

Read one line from the stream, with the provided encoding.

Parameters
stream
encoding
Returns

◆ ReadLines() [1/4]

IEnumerable< string > PeanutButter.Utils.StreamExtensions.ReadLines ( this Stream stream)
static

Reads the stream, line-for-line, with the UTF8 encoding.

Parameters
stream
Returns

◆ ReadLines() [2/4]

IEnumerable< string > PeanutButter.Utils.StreamExtensions.ReadLines ( this Stream stream,
Action< Eol > onNewline )
static

Reads the stream, line-for-line, with the UTF8 encoding. When a newline is encountered, the onNewLine func is called with the kind of line ending last encountered.

Parameters
stream
onNewline
Returns

◆ ReadLines() [3/4]

IEnumerable< string > PeanutButter.Utils.StreamExtensions.ReadLines ( this Stream stream,
Encoding encoding )
static

Reads the stream, line-for-line, with the provided encoding.

Parameters
stream
encoding
Returns

◆ ReadLines() [4/4]

IEnumerable< string > PeanutButter.Utils.StreamExtensions.ReadLines ( this Stream stream,
Encoding encoding,
Action< Eol > onNewLine )
static

Reads the stream, line-for-line, with the provided encoding. When a newline is encountered, the onNewLine func is called with the kind of line ending last encountered.

Parameters
stream
encoding
onNewLine
Returns

◆ Rewind()

void PeanutButter.Utils.StreamExtensions.Rewind ( this Stream src)
static

Rewinds the current stream pointer to the beginning of the stream (when supported by the stream)

Parameters
srcSource stream to rewind

◆ Save()

void PeanutButter.Utils.StreamExtensions.Save ( this Stream stream,
string filePath )
static

Saves a stream to a local file.

Parameters
stream
filePath

◆ SaveAsync()

async Task PeanutButter.Utils.StreamExtensions.SaveAsync ( this Stream stream,
string filePath )
static

Saves a stream to a local file.

Parameters
stream
filePath

◆ WriteAllBytes()

void PeanutButter.Utils.StreamExtensions.WriteAllBytes ( this Stream source,
byte[] data )
static

Writes all given bytes to a stream.

Parameters
sourceTarget stream to write to
dataBinary data to write
Exceptions
IOExceptionThrown when the target stream is null

◆ WriteAllBytesAsync()

async Task PeanutButter.Utils.StreamExtensions.WriteAllBytesAsync ( this Stream source,
byte[] data )
static

Writes all given bytes to a stream.

Parameters
sourceTarget stream to write to
dataBinary data to write
Exceptions
IOExceptionThrown when the target stream is null

◆ WriteString() [1/2]

void PeanutButter.Utils.StreamExtensions.WriteString ( this Stream stream,
string data )
static

Invokes WriteString() with the UTF8 Encoding.

Parameters
streamStream to operate on
dataString data to write

◆ WriteString() [2/2]

void PeanutButter.Utils.StreamExtensions.WriteString ( this Stream stream,
string data,
Encoding encoding )
static

Writes a string to a stream with the provided encoding.

Parameters
streamStream to write to
dataString data to write
encodingEncoding to use

◆ WriteStringAsync() [1/2]

async Task PeanutButter.Utils.StreamExtensions.WriteStringAsync ( this Stream stream,
string data )
static

Invokes WriteString() with the UTF8 Encoding.

Parameters
streamStream to operate on
dataString data to write

◆ WriteStringAsync() [2/2]

async Task PeanutButter.Utils.StreamExtensions.WriteStringAsync ( this Stream stream,
string data,
Encoding encoding )
static

Writes a string to a stream with the provided encoding.

Parameters
streamStream to write to
dataString data to write
encodingEncoding to use

The documentation for this class was generated from the following file:
  • source/Utils/PeanutButter.Utils/StreamExtensions.cs