当前位置: 首页>>代码示例>>C#>>正文


C# MemoryStream.AsRandomAccessStream方法代码示例

本文整理汇总了C#中MemoryStream.AsRandomAccessStream方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.AsRandomAccessStream方法的具体用法?C# MemoryStream.AsRandomAccessStream怎么用?C# MemoryStream.AsRandomAccessStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemoryStream的用法示例。


在下文中一共展示了MemoryStream.AsRandomAccessStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Open

    public async void Open(TextBox display)
    {
        try
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            picker.FileTypeFilter.Add(textExt);
            picker.FileTypeFilter.Add(compressedExt);
            StorageFile file = await picker.PickSingleFileAsync();
            switch (file.FileType)
            {
                case textExt:
                    display.Text = await FileIO.ReadTextAsync(file);
                    break;
                case compressedExt:
                    using (MemoryStream stream = new MemoryStream())
                    using (IInputStream input = await file.OpenSequentialReadAsync())
                    using (Decompressor decompressor = new Decompressor(input))
                    using (IRandomAccessStream output = stream.AsRandomAccessStream())
                    {
                        long inputSize = input.AsStreamForRead().Length;
                        ulong outputSize = await RandomAccessStream.CopyAsync(decompressor, output);
                        output.Seek(0);
                        display.Text = await new StreamReader(output.AsStream()).ReadToEndAsync();
                        Show(string.Format("Decompressed {0} bytes to {1} bytes",
                            inputSize, outputSize), "Compression App");
                    }
                    break;
                default:
                    break;
            }
        }
        catch
        {

        }
    }
开发者ID:RoguePlanetoid,项目名称:Windows-10-Universal-Windows-Platform,代码行数:37,代码来源:Library.cs

示例2: Save

    public async void Save(TextBox display)
    {
        try
        {
            StringBuilder text = new StringBuilder();
            FileSavePicker picker = new FileSavePicker();
            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            picker.FileTypeChoices.Add("Text File", new List<string>() { textExt });
            picker.FileTypeChoices.Add("Compressed File", new List<string>() { compressedExt });
            picker.DefaultFileExtension = textExt;
            StorageFile file = await picker.PickSaveFileAsync();
            switch (file.FileType)
            {
                case textExt:
                    await FileIO.WriteTextAsync(file, display.Text);
                    break;
                case compressedExt:
                    using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(display.Text)))
                    using (IRandomAccessStream input = stream.AsRandomAccessStream())
                    using (IRandomAccessStream output = await file.OpenAsync(FileAccessMode.ReadWrite))
                    using (Compressor compressor = new Compressor(output.GetOutputStreamAt(0), algorithm, 0))
                    {
                        ulong inputSize = await RandomAccessStream.CopyAsync(input, compressor);
                        bool finished = await compressor.FinishAsync();
                        ulong outputSize = output.Size;
                        Show(string.Format("Compressed {0} bytes to {1} bytes",
                            inputSize, outputSize), "Compression App");
                    }
                    break;
                default:
                    break;
            }
        }
        catch
        {

        }
    }
开发者ID:RoguePlanetoid,项目名称:Windows-10-Universal-Windows-Platform,代码行数:38,代码来源:Library.cs


注:本文中的MemoryStream.AsRandomAccessStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。