diff --git a/src/Uno.UWP/Storage/StorageFile.Base.cs b/src/Uno.UWP/Storage/StorageFile.Base.cs index 3b8ace8c0d80..81081f8d1357 100644 --- a/src/Uno.UWP/Storage/StorageFile.Base.cs +++ b/src/Uno.UWP/Storage/StorageFile.Base.cs @@ -8,6 +8,7 @@ using System.Threading.Tasks; using Windows.Storage.FileProperties; using Windows.Storage.Streams; +using Buffer = Windows.Storage.Streams.Buffer; namespace Windows.Storage { @@ -71,7 +72,7 @@ public virtual async Task CopyAndReplace(CancellationToken ct, IStorageFile targ using (var src = await Owner.OpenStreamForReadAsync()) using (var dst = await target.OpenStreamForReadAsync()) { - await src.CopyToAsync(dst, 8192, ct); + await src.CopyToAsync(dst, Buffer.DefaultCapacity, ct); } } @@ -86,7 +87,7 @@ public virtual async Task MoveAndReplace(CancellationToken ct, IStorageFile targ using (var src = await Owner.OpenStreamForReadAsync()) using (var dst = await target.OpenStreamForReadAsync()) { - await src.CopyToAsync(dst, 8192, ct); + await src.CopyToAsync(dst, Buffer.DefaultCapacity, ct); } await Delete(ct, StorageDeleteOption.PermanentDelete); diff --git a/src/Uno.UWP/Storage/StorageFile.cs b/src/Uno.UWP/Storage/StorageFile.cs index d4631489c085..392c9b20e157 100644 --- a/src/Uno.UWP/Storage/StorageFile.cs +++ b/src/Uno.UWP/Storage/StorageFile.cs @@ -21,6 +21,9 @@ public sealed partial class StorageFile : StorageItem, IStorageFile public static IAsyncOperation GetFileFromPathAsync(string path) => AsyncOperation.FromTask(async ct => new StorageFile(new Local(path))); + internal static StorageFile GetFileFromPath(string path) + => new StorageFile(new Local(path)); + internal static StorageFile GetFileFromLocalPath(string path) => new StorageFile(new Local(path)); diff --git a/src/Uno.UWP/Storage/StreamedFileDataRequestedHandler.cs b/src/Uno.UWP/Storage/StreamedFileDataRequestedHandler.cs index 7dbd369eef3b..11084d2d2556 100644 --- a/src/Uno.UWP/Storage/StreamedFileDataRequestedHandler.cs +++ b/src/Uno.UWP/Storage/StreamedFileDataRequestedHandler.cs @@ -23,7 +23,7 @@ namespace Windows.Storage // { // method ??= HttpMethod.Get; // client ??= new HttpClient(); - + // return req => Task.Run(() => FetchAsync(req, uri, method, client, onReady, req.CancellationToken)); // } @@ -59,7 +59,7 @@ namespace Windows.Storage // if (response.Content is { } content) // { // var responseStream = await content.ReadAsStreamAsync(); - // await responseStream.CopyToAsync(req.AsStreamForWrite(), 8192, ct); + // await responseStream.CopyToAsync(req.AsStreamForWrite(), global::Windows.Storage.Streams.Buffer.DefaultCapacity, ct); // } // } // catch (Exception e) diff --git a/src/Uno.UWP/Storage/Streams/Buffer.cs b/src/Uno.UWP/Storage/Streams/Buffer.cs index e9daa59ab704..c7f72d74ec27 100644 --- a/src/Uno.UWP/Storage/Streams/Buffer.cs +++ b/src/Uno.UWP/Storage/Streams/Buffer.cs @@ -6,6 +6,11 @@ namespace Windows.Storage.Streams { public partial class Buffer : IBuffer { + /// + /// A default length to use for buffer copy when none specified + /// + internal const int DefaultCapacity = 1024 * 1024; // 1M + private readonly Memory _data; internal static Buffer Cast(IBuffer impl) diff --git a/src/Uno.UWP/Storage/Streams/StreamedUriDataLoader.cs b/src/Uno.UWP/Storage/Streams/StreamedUriDataLoader.cs index 9979ca6a2464..913016597f99 100644 --- a/src/Uno.UWP/Storage/Streams/StreamedUriDataLoader.cs +++ b/src/Uno.UWP/Storage/Streams/StreamedUriDataLoader.cs @@ -84,9 +84,9 @@ private async Task Download(HttpResponseMessage response, CancellationToken ct) using var responseStream = await response.Content.ReadAsStreamAsync(); using var file = File.OpenWeak(FileAccess.Write); - var buffer = new byte[8192]; + var buffer = new byte[Buffer.DefaultCapacity]; int read; - while ((read = await responseStream.ReadAsync(buffer, 0, 8192, ct)) > 0) + while ((read = await responseStream.ReadAsync(buffer, 0, Buffer.DefaultCapacity, ct)) > 0) { await file.WriteAsync(buffer, 0, read, ct);