[CSHARP-2937] Use MemoryStream.GetBuffer instead of ToArray when targetting netstandard2.0 Created: 07/Feb/20  Updated: 15/Apr/21  Resolved: 15/Apr/21

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Robert Stam Assignee: Mikalai Mazurenka (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Enable features that can now be supported when targetting netstandard2.0

 Comments   
Comment by Mikalai Mazurenka (Inactive) [ 15/Apr/21 ]

There are 9 total occurrences of MemoryStream class throughout the solution (test projects are excluded):
1. BsonExtensionMethods.ToBson
MemoryStream.GetBuffer() usage is not applicable, because .ToBson() is a public method with byte[] return type, while .GetBuffer() usage requires slicing, otherwise technical size (multiplies of 256) is used, which is definitely not what we intent to do (.ToArray() slices the buffer appropriately).
2. BsonReader.ReadRawBsonArray
Already uses .GetBuffer().
3. BsonStreamAdapter.ReadCStringBytes
Already uses .GetBuffer().
4. RawBsonArray.Materialize
MemoryStream is used as Stream, which does not privide access to .ToArray() and .GetBuffer() methods.
5. CommandMessageFieldEncryptor.CombineCommandMessageSectionsIntoSingleDocument
MemoryStream is used as Stream, which does not privide access to .ToArray() and .GetBuffer() methods.
6. 4 occurrences in GridFSBucket of the same nature
In all 4 occurrences MemoryStream is used as Stream, which does not privide access to .ToArray() and .GetBuffer() methods.

As a summary, no changes are possible to make in scope of this ticket, thus closing it as implemented.

Generated at Wed Feb 07 21:43:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.