tags:

views:

116

answers:

2

Hi,

I get from server images and videos by stream. Now I'm saving it:

 Stream str = client.GetFile(path);
                    using (var outStream = new FileStream(@"c:\myFile.jpg", FileMode.Create))
                    {
                        var buffer = new byte[4096];
                        int count;
                        while ((count = str.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            outStream.Write(buffer, 0, count);
                        }
                    }

I can be jpg, mpg, flv and a lot of other multimedia types (Before I get stream I know what is a extension of this file).

Now I want to not save it , but run direct from stream.

Examples:

I get stream which is mybirthay.avi and I call my method RunFile(stream) and I think this method should works like System.Diagnostics.Process.Start(path), so my stream should be opened by default program in my SO for example allplayer.

I get stream from myfile.jpg and it is opening by irfanview,

etc...

Is it possible ??

+1  A: 

Windows puts up a wall between processes so they cannot directly access each other's memory without going through privileged debug-like API functions like ReadProcessMemory. This is what keeps the operating system stable and secure. But spells doom for what you are trying to accomplish.

You'll need to use a file. It won't be much slower than direct memory access, the file system cache takes care of that.

Hans Passant
+1  A: 

If you are set on not saving the stream to the disk, you could use something like Eldos' Callback File System: http://www.eldos.com/cbfs/

Or, use a ramdisk, save your stream there, and shell to that file location.

Eric Dahlvang