Beginner Stream Type Question

S-Soft 646 Reputation points
2022-11-05T00:17:21.527+00:00

Hi,
I need to pass some files on disk as stream to a 3rd party SDK for some processing and don't know if I should use FileStream or MemoryStream?

When reading, there are files on disk that I load and pass to the SDK to extract some data from:
Using memStream As New MemoryStream(File.ReadAllBytes("c:\blah.ext"), FileMode.Open, FileAccess.Read)

This file can be big, so I guess should be using FileStream:
Using fileStream As New FileStream("c:\blah.ext", FileMode.Open, FileAccess.Read)

Am I right?
If using FileStream, the file is just opened as read-only in-place?

2nd scenario is writing, what's the advise on it?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,524 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,636 questions
{count} votes

2 answers

Sort by: Most helpful
  1. P a u l 10,411 Reputation points
    2022-11-05T00:35:25.437+00:00

    Correct, FileStream would be the appropriate stream class to use for reading buffered file data from disk.

    Where do you need to write the data to?

    0 comments No comments

  2. Jiachen Li-MSFT 27,836 Reputation points Microsoft Vendor
    2022-11-10T07:24:37.967+00:00

    Hi @S-Soft ,
    Based on what kind of input is required by the SDK.
    You can choose a different FileAccess Enum for FileStream (String, FileMode, FileAccess).

    Read
    Read access to the file. Data can be read from the file. Combine with Write for read/write access.

    ReadWrite
    Read and write access to the file. Data can be written to and read from the file.

    Write
    Write access to the file. Data can be written to the file. Combine with Read for read/write access.

    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments