private static async Task WriteBufferTaskAsync(string path, IBuffer buffer, CancellationToken cancellationToken) { if (path is null) { throw new ArgumentNullException(nameof(path)); } var file = await StorageFile.GetFileFromPathAsync(path); await FileIO.WriteBufferAsync(file, buffer).AsTask(cancellationToken); }
/// <summary> /// Store data to file. /// </summary> /// <param name="folder">Folder of file.</param> /// <param name="fileName">Name of file.</param> /// <param name="options"><see cref="CreationCollisionOption"/> for the operation.</param> /// <param name="buffer">Data to store.</param> /// <returns>The stored file.</returns> public static IAsyncOperation <StorageFile> SaveFileAsync(this StorageFolder folder, string fileName, CreationCollisionOption options, IBuffer buffer) { if (folder == null) { throw new ArgumentNullException(nameof(folder)); } return(Run(async token => { fileName = StorageHelper.ToValidFileName(fileName); var file = await folder.CreateFileAsync(fileName, options); await FileIO.WriteBufferAsync(file, buffer); return file; })); }
async public static Task WriteBufferAsync(this StorageFile file, IBuffer buffer) { await FileIO.WriteBufferAsync(file, buffer); }