The IRandomAccessStream has a method called GetInputStreamAt http://msdn.microsoft.com/en-US/library/windows/apps/windows.storage.streams.irandomaccessstream
IInputStream inputStream = stream.GetInputStreamAt(0);
This gets you an IInputStream.
The IInputStream interface defines just one method, ReadAsync, which lets you read bytes into an IBuffer object. Windows.Storage.Stream also includes a DataReader class that you create based on an IInputStream object and then read numerous .NET objects from the stream as well as arrays of bytes. http://www.charlespetzold.com/blog/2011/11/080203.html , http://msdn.microsoft.com/library/windows/apps/BR208119
using (var stream = new InMemoryRandomAccessStream())
{
// for example, render pdf page
var pdfPage = document.GetPage((uint)i);
await pdfPage.RenderToStreamAsync(stream);
// then, write page to file
using (var reader = new DataReader(stream))
{
await reader.LoadAsync((uint)stream.Size);
var buffer = new byte[(int)stream.Size];
reader.ReadBytes(buffer);
await Windows.Storage.FileIO.WriteBytesAsync(file, buffer);
}
}
now you have a buffer containing all the read bytes.
you can now save this buffer to a file http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html
var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("MyWav.wav", Windows.Storage.CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteBytesAsync(file, buffer);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…