Load external file - MemoryStream help

dxmedia

Member
Joined
Jul 2, 2010
Messages
16
Programming Experience
1-3
Hi,

I am trying to modify this function that load an external file.

Instead of it writing bit by bit to the 'Stream' IOStream, I would like to write the data to a temporary MemoryStream, and then write it to 'Stream' all at once. I think this should be right before the 'Stream.Close()' line.

Can you help me ?

Here is my current code:

VB.NET:
        Dim FromStream As System.IO.Stream = Nothing

        FromStream = GetFileStream(Path)

        If Not FromStream Is Nothing Then

            Const Size As Integer = 256 * 1024
            Dim buffer(Size) As Byte
            Dim ReadBytes As Integer

            While True
                ReadBytes = FromStream.Read(buffer, 0, Size)
                If ReadBytes = 0 Then Exit While
                Try
                    Stream.Write(buffer, 0, ReadBytes)
                Catch e As System.IO.IOException
                    ' Loading is interrupted
                    Exit While
                End Try
            End While

            Stream.Close()
            Handled = True
        End If


Thanks
 
Ok,

Solved it.

I managed to copy information from a temporary MemoryStream to the actual target Stream:

Stream.Write(tempMemoryStream.ToArray(), 0, tempMemoryStream.length)
 
Back
Top