mercredi 23 avril 2014

How to first read and the write to a file


Vote count:

0




I am trying to read tags, change tags,, and then and write back data to the same file. Reading tags is no problem but write are not working. Data seems not to be saved to disk.


My test case.



var file = await KnownFolders.MusicLibrary.GetFileAsync("sampleUnderTest.wav");
var content = await ReadFileAsynch(file);

content.Add("newTag","newValue")
await SubmittFileAsynch(file, content)
var newContent = await ReadFileAsynch(file);

Assert.NotEqual(content,newContent)


The Assert throws a Exception because content and newContent are identical.


This is part my code:



public async Task SubmittFileAsynch(StorageFile file, Content content)
{
var accessStream = await file.OpenAsync(FileAccessMode.ReadWrite);
using (accessStream)
await CommitAsynch(accessStream, content);
}


internal async Task CommitAsynch(IRandomAccessStream accessStream, Content content)
{
List<byte[]> tbw = new List<byte[]>();
using (var InStream = accessStream.AsStreamForRead())
{
using (var br = new BinaryReader(InStream))
{
//Reads file until it reaches the part of the containing tags and
//that are going to be modified by content.
//tbw is created from data in content and from the read process.
await BuildAsync(br, content, tbw);

using (var outstream = (accessStream.GetOutputStreamAt(0)))
using (var bw = new DataWriter(outstream))
{
await CommitAsync(tbw, bw);
await bw.FlushAsync();
}
}
}
}

private async Task CommitAsync(List<byte[]> tbw, DataWriter bw)
{
await Task.Run(() =>
{
foreach (byte[] buf in tbw)
bw.WriteBytes(buf);
});

}


I can't see what I am doing wrong ,, and are hoping for some help.


//lg



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire