Monday, July 29, 2013

How to write file chunk by chunk in WinRT?

I am trying to write buffer data into a file. I receive buffer data in a callback function continuously. I need to read the buffer and save it in a file as it is received. This will be repeated till i get complete file,i get data chunk of 4k in size. But below code either throws an exception or output file is corrupted. Please let me know how to do this in winRT.


Here is the code snippet.



StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(strFileName, Windows.Storage.CreationCollisionOption.ReplaceExisting);
public async void Receive(byte[] buffer)
{
using
(var ostream = await file.OpenStreamForWriteAsync())
{
await ostream
.WriteAsync(buffer, 0, buffer.Length);
}
}

No comments:

Post a Comment