What would be the main difference between the two?
The Stream
is an abstract class basis for all streams (fuller definition) that may exist, so you can encode algorithms that need to stream without knowing where they come from and go.
Already MemoryStream
is a concrete class, obviously derived from Stream
as can be observed in question code, and works with data streams in raw memory.
There are advantages to performance gain?
In relation to what? Between one of them? As one is abstract can even be compared. If go with others need to see the implementation of each, depends on the hardware where it works.
For web use, which is the most appropriate?
Between the two will always be the concrete class since the abstract does nothing. If you want to compare to other things it makes no sense to analyze the use for web, web development is too generic to define something.
Among the streams existing on . NET does not see another that could be used for web specifically, but overall yes. It is possible to use some other third party or develop your own. The documentation linked above has all. NET classes that inherit from Stream
.
Your case
If what you are doing works and meets all the requirements you want in all situations, that is, if it is right, ok. It seems to me that this case is ok, is loading a PDF with specific API and throwing it into memory as this API allows. I’ll guess it’s not necessary to be a stream in the case, but I do not know if the PDF viewer API has another way to access. If the intention is to send directly to another location then it may be that another is more suitable, but by the question we have no way of knowing.
The problem in general occurs because people do not read the documentation, do not understand side points and do not test all situations that may occur, in general the person tests to work, when the right is to test to not work and find out where can give problem and avoid it.
As the main method (that calls this
bytetoStrem
) loads this array of PDF bytes? Is it an API that returns to it? Or do you read from a folder on the server itself?– Alisson