Skip to content

Commit 866528c

Browse files
committed
Add GetBuffer to MemoryStream
- Remove exposing internals to HTTP.
1 parent 408f9a0 commit 866528c

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

System.IO.Streams/MemoryStream.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// See LICENSE file in the project root for full license information.
55
//
66

7-
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Net.Http, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")]
8-
97
namespace System.IO
108
{
119
/// <summary>
@@ -14,7 +12,7 @@ namespace System.IO
1412
public class MemoryStream : Stream
1513
{
1614
// Either allocated internally or externally.
17-
internal byte[] _buffer;
15+
private byte[] _buffer;
1816
// For user-provided arrays, start at this origin
1917
private int _origin;
2018
// read/write head.
@@ -177,6 +175,23 @@ public override void Flush()
177175
{
178176
}
179177

178+
/// <summary>
179+
/// Returns the array of unsigned bytes from which this stream was created.
180+
/// </summary>
181+
/// <returns>The byte array from which this stream was created, or the underlying array if a byte array was not provided to the <see cref="MemoryStream"/> constructor during construction of the current instance.</returns>
182+
/// <remarks>
183+
/// <para>
184+
/// Note that the buffer contains allocated bytes which might be unused. For example, if the string "test" is written into the <see cref="MemoryStream"/> object, the length of the buffer returned from <see cref="GetBuffer"/> is 256, not 4, with 252 bytes unused. To obtain only the data in the buffer, use the <see cref="ToArray"/> method; however, <see cref="ToArray"/> creates a copy of the data in memory.
185+
/// </para>
186+
/// <para>
187+
/// The buffer can also be <see langword="null"/>.
188+
/// </para>
189+
/// </remarks>
190+
public virtual byte[] GetBuffer()
191+
{
192+
return _buffer;
193+
}
194+
180195
/// <inheritdoc/>
181196
public override long Length
182197
{

0 commit comments

Comments
 (0)