-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement TranscodingStream, a streaming equivalent of Encoding.Convert #35145
Implement TranscodingStream, a streaming equivalent of Encoding.Convert #35145
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @tarekgh |
And yes, I know I have array pool rentals inside a try / finally block. This follows the pattern already established by |
7a363e1
to
1155286
Compare
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Encoding/tests/Encoding/TranscodingStreamTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Text/TranscodingStream.cs
Show resolved
Hide resolved
src/libraries/System.Text.Encoding/tests/Encoding/TranscodingStreamTests.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating System.Net.Http.Json
as well.
Resolves #30260.
The general idea is that if you have an inner
Stream
which represents machine-readable text under one encoding (say, shift-jis), this allows creating a wrappingStream
which represents that same machine-readable text under a different encoding (say, UTF-8). The primary scenario for this is as an adapter where you have System.Text.Json (as UTF-8) working on the outerStream
but where the client needs the response payload in a different encoding.Usage (showing writing)
Note: When writing, the call to
Stream.Close
/Stream.Dispose
/Stream.DisposeAsync
is the thing that flushes the underlyingEncoder
/Decoder
instances. This shouldn't normally matter as long as the caller isn't trying to write ill-formed data to the outerStream
. But if the caller does emit an incomplete multi-byte sequence (say, the UTF-8 bytes[ E0 BF ]
) at the end of the stream, the fallback mechanism won't be invoked until the outer stream is disposed.