filipnavara / CodeSign

MIT License
19 stars 4 forks source link

Consider Nerdbank.Streams #7

Open qmfrederik opened 2 years ago

qmfrederik commented 2 years ago

There's some overlap with Melanzana.Streams:

Would you consider taking Nerdbank.Streams as a dependency if I can convince @AArnott to take PRs which add write support for NestedStream, add the equivalent of Unclosable[MemoryStream] and WritePadding?

I'm asking because I always encounter the need for the same set of stream extensions / specialized substream classes, and it would be nice to consolidate them into a single project.

Not a priority but perhaps nice to have.

filipnavara commented 2 years ago

There's Stream.ReadExactly API in .NET 7 so I was going to change the name and keep ReadFully implementation only for compatibility with down-level frameworks (under the ReadExactly name).

For the SliceStream, I am not sure. I would like to keep the dependencies to a minimum, but I am not opposed to Nerdbank.Streams if it brings some benefits. I am consuming the library along with LibObjectFile to write DWARF information and that also has its own SliceStream.

filipnavara commented 2 years ago

Btw, I think we don't need a write support actually. The current use of SliceStream is for referencing original content when rewriting sections/segments. When asking for writable streams we always use MemoryStream (or UnclosableMemoryStream).

AArnott commented 2 years ago

I'm open to discuss. I wonder how a writable NestedStream would work, but I guess it's irrelevant if that functionality isn't required here. UnclosableMemoryStream sounds like you want to share out the stream without worrying that the receivers will dispose of it. It's so simple to declare that I wonder at the value of adding it to a shared library. I might also declare it as a new Stream that just wraps an original MemoryStream and passes all calls through except Dispose. That will make it applicable to all stream types, and protect even the Dispose() method itself from being called.