NanoByte.Common
2.6.1
|
Provides Stream-related helper methods. More...
Static Public Member Functions | |
static byte[] | Read (this Stream stream, int count) |
Reads a fixed number of bytes from a stream starting from the current offset. More... | |
static ? byte[] | TryRead (this Stream stream, int count) |
Reads a fixed number of bytes from a stream starting from the current offset. More... | |
static byte[] | ToArray (this Stream stream) |
Reads the entire content of a stream to an array. Seeks to the beginning of the stream if Stream.CanSeek. More... | |
static string | ReadToString (this Stream stream, Encoding? encoding=null) |
Reads the entire content of a stream as string data. Seeks to the beginning of the stream if Stream.CanSeek. More... | |
static void | CopyToEx (this Stream source, Stream destination, int bufferSize=4096, CancellationToken cancellationToken=default, IProgress< long >? progress=null) |
Copies the content of one stream to another. Seeks to the beginning of the source stream if Stream.CanSeek. More... | |
static void | CopyToFile (this Stream stream, [Localizable(false)] string path, int bufferSize=4096, CancellationToken cancellationToken=default, IProgress< long >? progress=null) |
Writes the entire content of a stream to a file. More... | |
static void | Write (this Stream stream, byte[] data) |
Writes the entire contents of an array to a stream. More... | |
static bool | ContentEquals (this Stream stream1, Stream stream2) |
Compares two streams for bit-wise equality. Seeks to the beginnings of the streams if Stream.CanSeek. More... | |
static MemoryStream | ToStream (this string data, Encoding? encoding=null) |
Creates a new MemoryStream and fills it with string data. More... | |
static Stream | GetEmbeddedStream (this Type type, [Localizable(false)] string name) |
Returns an embedded resource as a stream. More... | |
static byte[] | GetEmbeddedBytes (this Type type, [Localizable(false)] string name) |
Returns an embedded resource as a byte array. More... | |
static string | GetEmbeddedString (this Type type, [Localizable(false)] string name, Encoding? encoding=null) |
Returns an embedded resource as a string. More... | |
static void | CopyEmbeddedToFile (this Type type, [Localizable(false)] string name, [Localizable(false)] string path) |
Copies an embedded resource to a file. More... | |
Provides Stream-related helper methods.
|
inlinestatic |
Compares two streams for bit-wise equality. Seeks to the beginnings of the streams if Stream.CanSeek.
Will try to Stream.Seek to the start of both streams.
|
inlinestatic |
Copies an embedded resource to a file.
type | A type that is located in the same namespace as the embedded resource. |
name | The name of the embedded resource. |
path | The path of the file to write. |
ArgumentException | The specified embedded resource does not exist. |
|
inlinestatic |
Copies the content of one stream to another. Seeks to the beginning of the source stream if Stream.CanSeek.
source | The source stream to copy from. |
destination | The destination stream to copy to. |
bufferSize | The size of the buffer to use for copying in bytes. |
cancellationToken | Used to signal when the user wishes to cancel the copy process. |
progress | Used to report back the number of bytes that have been copied so far. |
Will try to Stream.Seek to the start of source .
|
inlinestatic |
Writes the entire content of a stream to a file.
stream | The stream to read from. |
path | The path of the file to write. |
bufferSize | The size of the buffer to use for copying in bytes. |
cancellationToken | Used to signal when the user wishes to cancel the copy process. |
progress | Used to report back the number of bytes that have been copied so far. Callbacks are rate limited to once every 250ms. |
|
inlinestatic |
Returns an embedded resource as a byte array.
type | A type that is located in the same namespace as the embedded resource. |
name | The name of the embedded resource. |
ArgumentException | The specified embedded resource does not exist. |
|
inlinestatic |
Returns an embedded resource as a stream.
type | A type that is located in the same namespace as the embedded resource. |
name | The name of the embedded resource. |
ArgumentException | The specified embedded resource does not exist. |
|
inlinestatic |
Returns an embedded resource as a string.
type | A type that is located in the same namespace as the embedded resource. |
name | The name of the embedded resource. |
encoding | The encoding of the string; leave null to default to UTF8Encoding. |
ArgumentException | The specified embedded resource does not exist. |
|
static |
Reads a fixed number of bytes from a stream starting from the current offset.
stream | The stream to read from. |
count | The number of bytes to read. |
IOException | The desired number of bytes could not be read from the stream. |
|
inlinestatic |
Reads the entire content of a stream as string data. Seeks to the beginning of the stream if Stream.CanSeek.
stream | The stream to read from. |
encoding | The encoding of the string; leave null to default to UTF8Encoding. |
|
inlinestatic |
Reads the entire content of a stream to an array. Seeks to the beginning of the stream if Stream.CanSeek.
stream | The stream to read from. |
|
inlinestatic |
Creates a new MemoryStream and fills it with string data.
data | The data to fill the stream with. |
encoding | The encoding of the string; leave null to default to UTF8Encoding. |
|
inlinestatic |
Reads a fixed number of bytes from a stream starting from the current offset.
stream | The stream to read from. |
count | The number of bytes to read. |
null
if the desired number of bytes could not be read from the stream .
|
inlinestatic |
Writes the entire contents of an array to a stream.
stream | The stream to write to. |
data | The array containing the bytes to write. |