writeBytesAsync from a blob


  • I'm creating a blob from a canvas using canvas.msToBlob();  I need to then write this data to a storageFile.  I have attempted to use FileIO.WriteBytesAsync to write the data but it expects an array of numbers.  What is the best way to do what I'm trying to do.  I either need a way to convert the blob to array of numbers, or save the canvas data in some other format, or find another function that will write my blob to the file.  Any help?
    Tuesday, July 17, 2012 12:50 PM


  • Took some fiddling around but I believe I have it now. Assuming you have a canvas and storageFile.

    var stream = canvas.msToBlob().msDetachStream();
    var reader = new Windows.Storage.Streams.DataReader(stream);
    	.then(function() {
    		var buffer = reader.detachBuffer();
    		return Windows.Storage.FileIO.writeBufferAsync(storageFile, buffer);
    	.done(function() {
    		alert('All done!');

    Tuesday, July 17, 2012 1:31 PM