As discussed before, when a BinaryReader or BinaryWriter gets closed, its underlying Stream get closed as well (aargh). Consider this situation: a routine R
is passed a MemoryStream, say M
; I would like to write some stuff to M
and then pass it to another routine for more processing (not necessarily writing). For convenience, I'd like to wrap M
in a BinaryWriter to do my writing. After writing, I'm done with the BinaryWriter but not with M
.
void R(MemoryStream M)
{
using (B = new BinaryWriter(M))
{
// write some stuff using B
}
S(M); // now pass M to another routine for further processing
}
But, I can't dispose of the BinaryStream without closing M
.
Q: Is there a way to do any of the following?
To do this, you'll need to use Git on the command line. You can practice setting the upstream repository using the same octocat/Spoon-Knife repository you just forked. On GitHub.com, navigate to the octocat/Spoon-Knife repository. In the top-right corner of the page, click Fork . To learn more about GitHub CLI, see " About GitHub CLI ."
To verify the new upstream repository you've specified for your fork, type git remote -v again. You should see the URL for your fork as origin, and the URL for the original repository as upstream. Now, you can keep your fork synced with the upstream repository with a few Git commands.
On GitHub.com, navigate to the octocat/Spoon-Knife repository. In the top-right corner of the page, click Fork . To learn more about GitHub CLI, see " About GitHub CLI ." To create a fork of a repository, use the gh repo fork subcommand. To create the fork in an organization, use the --org flag.
On GitHub.com, navigate to the octocat/Spoon-Knife repository. In the top-right corner of the page, click Fork . To learn more about GitHub CLI, see " About GitHub CLI ."
You should better get the underlying byte[] buffer using
byte[] buffer = ms.GetBuffer();
And then copy the byte data using the Array.Copy() method. You are free to create a new stream with it.
You can use things like the MiscUtil.IO.NonClosingStreamWrapper
in MiscUtil, which wraps a Stream
and simply ignores Close
/Dispose
requests. For just this purpose.
void R(MemoryStream M)
{
using (B = new BinaryWriter(new NonClosingStreamWrapper(M)))
{
// write some stuff using B
}
S(M); // now pass M to another routine for further processing
}
You can:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With