예제 #1
0
        public async Task <IReadOnlyList <IStorageItem> > GetItemsAsync()
        {
            var items = await FileHandle.InvokeAsync <IJSInProcessObjectReference?>("getItems");

            if (items is null)
            {
                return(Array.Empty <IStorageItem>());
            }

            var count = items.Invoke <int>("count");

            return(Enumerable.Range(0, count)
                   .Select(index =>
            {
                var reference = items.Invoke <IJSInProcessObjectReference>("at", index);
                return reference.Invoke <string>("getKind") switch
                {
                    "directory" => (IStorageItem) new JSStorageFolder(reference),
                    "file" => new JSStorageFile(reference),
                    _ => null
                };
            })
                   .Where(i => i is not null)
                   .ToArray() !);
        }
예제 #2
0
        public async Task <Stream> OpenReadAsync()
        {
            var stream = await FileHandle.InvokeAsync <IJSStreamReference>("openRead");

            // Remove maxAllowedSize limit, as developer can decide if they read only small part or everything.
            return(await stream.OpenReadStreamAsync(long.MaxValue, CancellationToken.None));
        }
예제 #3
0
        public async Task <Stream> OpenWriteAsync()
        {
            var properties = await FileHandle.InvokeAsync <FileProperties?>("getProperties");

            var streamWriter = await FileHandle.InvokeAsync <IJSInProcessObjectReference>("openWrite");

            return(new JSWriteableStream(streamWriter, (long)(properties?.Size ?? 0)));
        }