Getting a Stream from a resource file / content

Is this the correct/only way of getting a Stream from a resource file?

    Uri uri = new Uri(fullPath);

    StorageFile storageFile = 
      await Windows.Storage.StorageFile.

    IRandomAccessStreamWithContentType randomAccessStream = 
      await storageFile.OpenReadAsync();

    IInputStream resourceStream = (IInputStream)

All my other sources (http and local storage) return a Stream object, and it is painful to have to if-else code that uses one or the other.

I've also tried to just create a MemoryStream out of it, but I can't even find a way to get the bytes out... Please help.

    uint size = (uint)randomAccessStream.Size;
    IBuffer buffer = new Windows.Storage.Streams.Buffer(size);
    await randomAccessStream.ReadAsync(buffer, size, 

    Stream stream = new MemoryStream(buffer); // error takes byte[] not IBuffer

IInputStream.ReadAsync() when reading from resource:

while Stream.Read() and Stream.ReadAsync() look like this:




Ok I found it!

    StorageFile storageFile =
      await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri);

    var randomAccessStream = await storageFile.OpenReadAsync();
    Stream stream = randomAccessStream.AsStreamForRead();

You can also do it in one less line:

Stream stream = await storageFile.OpenStreamForReadAsync(); 

Need Your Help

How to sort files in some directory by the names on Linux

c linux file sorting scandir

I use opendir() and readdir() to display the file names in a directory. But they are disordered. How can I sort them? The language is C.

Typedef (alias) of an generic class

c++ templates

is it possible in C++ to create an alias of template class (without specifying parameters)?