Provides extension methods for copying streams
More...
|
static MemoryStream | CopyToMemoryStream (Stream s) |
| Copies the remaining data in the current stream to a new MemoryStream instance. More...
|
|
static MemoryStream | CopyToMemoryStream (Stream s, bool entireStream) |
| Copies the current stream into a new MemoryStream instance. More...
|
|
static MemoryStream | CopyToMemoryStream (Stream s, bool entireStream, int chunkSize) |
| Copies the current stream into a new MemoryStream instance. More...
|
|
static byte[] | CopyToBytes (Stream s) |
| Copies the remaining data in the current stream to a byte[] array of exact size. More...
|
|
static byte[] | CopyToBytes (Stream s, bool entireStream) |
| Copies the current stream into a byte[] array of exact size. More...
|
|
static void | CopyToStream (Stream s, Stream other) |
| Copies the remaining data from the this stream into the given stream. More...
|
|
static void | CopyToStream (Stream s, Stream other, bool entireStream) |
| Copies this stream into the given stream More...
|
|
static void | CopyToStream (Stream src, Stream dest, bool entireStream, int chunkSize) |
| Copies this stream into the given stream More...
|
|
static byte[] | CopyToBytes (Stream src, bool entireStream, int chunkSize) |
| Copies the current stream into a byte[] array of exact size More...
|
|
static byte[] | CopyOrReturnBuffer (Stream src, out long length, bool entireStream, int chunkSize) |
| Attempts to return a byte[] array containing the remaining portion of the stream. Unlike CopyToBytes(), does not return a byte[] array of exact length, and may re-use the actual Stream's byte array, making it unsafe to write to in the future. More...
|
|
Provides extension methods for copying streams
Definition at line 12 of file Stream.cs.
static byte [] ImageResizer.ExtensionMethods.StreamExtensions.CopyOrReturnBuffer |
( |
Stream |
src, |
|
|
out long |
length, |
|
|
bool |
entireStream, |
|
|
int |
chunkSize |
|
) |
| |
|
inlinestatic |
Attempts to return a byte[] array containing the remaining portion of the stream. Unlike CopyToBytes(), does not return a byte[] array of exact length, and may re-use the actual Stream's byte array, making it unsafe to write to in the future.
- Parameters
-
- Returns
Definition at line 189 of file Stream.cs.
Referenced by ImageResizer.Plugins.WicBuilder.WicBuilderPlugin.BuildJob().
190 if (src is MemoryStream) {
191 if (entireStream || src.Position == 0) {
194 MemoryStream ms = src as MemoryStream;
196 return ms.GetBuffer();
197 }
catch (UnauthorizedAccessException)
202 byte[] buf =
CopyToBytes(src, entireStream, chunkSize);
static byte[] CopyOrReturnBuffer(Stream src, out long length, bool entireStream, int chunkSize)
Attempts to return a byte[] array containing the remaining portion of the stream. Unlike CopyToBytes(...
static MemoryStream CopyToMemoryStream(Stream s)
Copies the remaining data in the current stream to a new MemoryStream instance.
static byte[] CopyToBytes(Stream s)
Copies the remaining data in the current stream to a byte[] array of exact size.
static byte [] ImageResizer.ExtensionMethods.StreamExtensions.CopyToBytes |
( |
Stream |
s | ) |
|
|
inlinestatic |
Copies the remaining data in the current stream to a byte[] array of exact size.
- Parameters
-
- Returns
Definition at line 51 of file Stream.cs.
static byte[] CopyToBytes(Stream s)
Copies the remaining data in the current stream to a byte[] array of exact size.
static byte [] ImageResizer.ExtensionMethods.StreamExtensions.CopyToBytes |
( |
Stream |
s, |
|
|
bool |
entireStream |
|
) |
| |
|
inlinestatic |
Copies the current stream into a byte[] array of exact size.
- Parameters
-
s | |
entireStream | True to copy entire stream if seeakable, false to only copy remaining data |
- Returns
Definition at line 60 of file Stream.cs.
static byte[] CopyToBytes(Stream s)
Copies the remaining data in the current stream to a byte[] array of exact size.
static byte [] ImageResizer.ExtensionMethods.StreamExtensions.CopyToBytes |
( |
Stream |
src, |
|
|
bool |
entireStream, |
|
|
int |
chunkSize |
|
) |
| |
|
inlinestatic |
Copies the current stream into a byte[] array of exact size
- Parameters
-
src | |
entireStream | True to copy entire stream if seeakable, false to only copy remaining data. |
chunkSize | The buffer size to use (in bytes) if a buffer is required. Default: 4KiB |
- Returns
Definition at line 134 of file Stream.cs.
136 if (src is MemoryStream) {
138 MemoryStream ms = src as MemoryStream;
140 byte[] buffer = ms.GetBuffer();
141 long pos = entireStream ? 0 : src.Position;
142 long count = src.Length - pos;
143 bytes =
new byte[count];
144 Array.Copy(buffer, pos, bytes, 0, count);
146 }
catch (UnauthorizedAccessException)
148 if (entireStream || src.Position == 0)
return ms.ToArray();
152 long pos = entireStream ? 0 : src.Position;
153 if (entireStream) src.Seek(0, SeekOrigin.Begin);
156 int numBytesToRead = (int)(src.Length - pos);
157 bytes =
new byte[numBytesToRead];
158 int numBytesRead = 0;
159 while (numBytesToRead > 0) {
161 int n = src.Read(bytes, numBytesRead, numBytesToRead);
170 Debug.Assert(numBytesRead == bytes.Length);
174 var ms =
new MemoryStream();
static void CopyToStream(Stream s, Stream other)
Copies the remaining data from the this stream into the given stream.
static byte[] CopyToBytes(Stream s)
Copies the remaining data in the current stream to a byte[] array of exact size.
static MemoryStream ImageResizer.ExtensionMethods.StreamExtensions.CopyToMemoryStream |
( |
Stream |
s | ) |
|
|
inlinestatic |
Copies the remaining data in the current stream to a new MemoryStream instance.
- Parameters
-
- Returns
Definition at line 19 of file Stream.cs.
static MemoryStream CopyToMemoryStream(Stream s)
Copies the remaining data in the current stream to a new MemoryStream instance.
static MemoryStream ImageResizer.ExtensionMethods.StreamExtensions.CopyToMemoryStream |
( |
Stream |
s, |
|
|
bool |
entireStream |
|
) |
| |
|
inlinestatic |
Copies the current stream into a new MemoryStream instance.
- Parameters
-
s | |
entireStream | True to copy entire stream if seeakable, false to only copy remaining data |
- Returns
Definition at line 28 of file Stream.cs.
static MemoryStream CopyToMemoryStream(Stream s)
Copies the remaining data in the current stream to a new MemoryStream instance.
static MemoryStream ImageResizer.ExtensionMethods.StreamExtensions.CopyToMemoryStream |
( |
Stream |
s, |
|
|
bool |
entireStream, |
|
|
int |
chunkSize |
|
) |
| |
|
inlinestatic |
Copies the current stream into a new MemoryStream instance.
- Parameters
-
s | |
entireStream | True to copy entire stream if seeakable, false to only copy remaining data |
chunkSize | The buffer size to use (in bytes) if a buffer is required. Default: 4KiB |
- Returns
Definition at line 39 of file Stream.cs.
40 MemoryStream ms =
new MemoryStream(s.CanSeek ? ((
int)s.Length + 8 - (entireStream ? 0 : (
int)s.Position)) : chunkSize);
static void CopyToStream(Stream s, Stream other)
Copies the remaining data from the this stream into the given stream.
static void ImageResizer.ExtensionMethods.StreamExtensions.CopyToStream |
( |
Stream |
s, |
|
|
Stream |
other |
|
) |
| |
|
inlinestatic |
Copies the remaining data from the this stream into the given stream.
- Parameters
-
s | |
other | The stream to write to |
Definition at line 68 of file Stream.cs.
static void CopyToStream(Stream s, Stream other)
Copies the remaining data from the this stream into the given stream.
static void ImageResizer.ExtensionMethods.StreamExtensions.CopyToStream |
( |
Stream |
s, |
|
|
Stream |
other, |
|
|
bool |
entireStream |
|
) |
| |
|
inlinestatic |
Copies this stream into the given stream
- Parameters
-
s | |
other | The stream to write to |
entireStream | True to copy entire stream if seeakable, false to only copy remaining data |
Definition at line 77 of file Stream.cs.
static void CopyToStream(Stream s, Stream other)
Copies the remaining data from the this stream into the given stream.
static void ImageResizer.ExtensionMethods.StreamExtensions.CopyToStream |
( |
Stream |
src, |
|
|
Stream |
dest, |
|
|
bool |
entireStream, |
|
|
int |
chunkSize |
|
) |
| |
|
inlinestatic |
Copies this stream into the given stream
- Parameters
-
src | |
dest | The stream to write to |
entireStream | True to copy entire stream if seeakable, false to only copy remaining data |
chunkSize | True to copy entire stream if seeakable, false to only copy remaining data |
Definition at line 92 of file Stream.cs.
93 if (entireStream && src.CanSeek) src.Seek(0, SeekOrigin.Begin);
95 if (src is MemoryStream && src.CanSeek) {
97 int pos = (int)src.Position;
98 dest.Write(((MemoryStream)src).GetBuffer(), pos, (int)(src.Length - pos));
100 }
catch (UnauthorizedAccessException)
103 if (dest is MemoryStream && src.CanSeek) {
105 int srcPos = (int)src.Position;
106 int pos = (
int)dest.Position;
107 int length = (int)(src.Length - srcPos) + pos;
108 dest.SetLength(length);
110 var data = ((MemoryStream)dest).GetBuffer();
111 while (pos < length) {
112 pos += src.Read(data, pos, length - pos);
115 }
catch (UnauthorizedAccessException)
118 int size = (src.CanSeek) ? Math.Min((
int)(src.Length - src.Position), chunkSize) : chunkSize;
119 byte[] buffer =
new byte[size];
122 n = src.Read(buffer, 0, buffer.Length);
123 dest.Write(buffer, 0, n);
The documentation for this class was generated from the following file:
- C:/Users/nathanael/Documents/resizer/Core/ExtensionMethods/Stream.cs