C# MemoryStream.SetLength的代码示例
通过代码示例来学习C# MemoryStream.SetLength方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
MemoryStream.SetLength是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的MemoryStream.SetLength() 已经帮大家高亮显示了,大家可以重点学习MemoryStream.SetLength() 方法的写法,从而快速掌握该方法的应用。
MemoryStream.SetLength的代码示例1 - RemoveLineTags()
using System.IO; public static MemoryStream RemoveLineTags(MemoryStream inputMemoryStream, string removeLineTag) { // // TODO: This method should be deprecated and/or removed. // Use FileGenerator or a derived class to build your output files, and call its // RemoveTaggedLines method. // // remove all line that contain RemoveLineTag inputMemoryStream.Seek(0, SeekOrigin.Begin); StreamReader streamReader = new StreamReader(inputMemoryStream); MemoryStream cleanMemoryStream = new MemoryStream((int)inputMemoryStream.Length); StreamWriter cleanWriter = new StreamWriter(cleanMemoryStream, new UTF8Encoding(true)); string readline = streamReader.ReadLine(); while (readline != null) { if (!readline.Contains(removeLineTag)) cleanWriter.WriteLine(readline); readline = streamReader.ReadLine(); } cleanWriter.Flush(); // removes the end of line from the last WriteLine to be consistent with VS project // output; this will stop the pointless "Do you want to refresh?" prompts because of a // new line. if (cleanMemoryStream.Length != 0) cleanMemoryStream.SetLength(cleanMemoryStream.Length - Environment.NewLine.Length); return cleanMemoryStream; }
开发者ID:ubisoft,项目名称:Sharpmake,代码行数:37,代码来源:Util.cs
在RemoveLineTags()方法中,MemoryStream的代码示例类中的SetLength的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.SetLength的代码示例2 - RenameAsync()
using System.IO; public override IAsyncAction RenameAsync(string desiredName, NameCollisionOption option) { return AsyncInfo.Run((cancellationToken) => SafetyExtensions.WrapAsync(async () => { if (Path == containerPath) { if (backingFile is not null) { await backingFile.RenameAsync(desiredName, option); } else { var fileName = IO.Path.Combine(IO.Path.GetDirectoryName(Path), desiredName); PInvoke.MoveFileFromApp(Path, fileName); } } else { var index = await FetchZipIndex(); if (index < 0) { return; } using (var ms = new MemoryStream()) { using (var archiveStream = await OpenZipFileAsync(FileAccessMode.Read)) { SevenZipCompressor compressor = new SevenZipCompressor() { CompressionMode = CompressionMode.Append }; compressor.SetFormatFromExistingArchive(archiveStream); var fileName = IO.Path.GetRelativePath(containerPath, IO.Path.Combine(IO.Path.GetDirectoryName(Path), desiredName)); await compressor.ModifyArchiveAsync(archiveStream, new Dictionary
() { { index, fileName } }, Credentials.Password, ms); } using (var archiveStream = await OpenZipFileAsync(FileAccessMode.ReadWrite)) { ms.Position = 0; await ms.CopyToAsync(archiveStream); await ms.FlushAsync(); archiveStream.SetLength(archiveStream.Position); } } } }, ((IPasswordProtectedItem)this).RetryWithCredentialsAsync)); }
开发者ID:files-community,项目名称:Files,代码行数:44,代码来源:ZipStorageFile.cs
在RenameAsync()方法中,MemoryStream的代码示例类中的SetLength的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.SetLength的代码示例3 - CreateFolderAsync()
using System.IO; public override IAsyncOperation
CreateFolderAsync(string desiredName, CreationCollisionOption options) { return AsyncInfo.Run((cancellationToken) => SafetyExtensions.Wrap (async () => { var zipDesiredName = System.IO.Path.Combine(Path, desiredName); var item = await GetItemAsync(desiredName); if (item is not null) { if (options != CreationCollisionOption.ReplaceExisting) { return null; } await item.DeleteAsync(); } using (var ms = new MemoryStream()) { using (var archiveStream = await OpenZipFileAsync(FileAccessMode.Read)) { SevenZipCompressor compressor = new SevenZipCompressor() { CompressionMode = CompressionMode.Append }; compressor.SetFormatFromExistingArchive(archiveStream); var fileName = IO.Path.GetRelativePath(containerPath, zipDesiredName); await compressor.CompressStreamDictionaryAsync(archiveStream, new Dictionary () { { fileName, null } }, Credentials.Password, ms); } using (var archiveStream = await OpenZipFileAsync(FileAccessMode.ReadWrite)) { ms.Position = 0; await ms.CopyToAsync(archiveStream); await ms.FlushAsync(); archiveStream.SetLength(archiveStream.Position); } } var folder = new ZipStorageFolder(zipDesiredName, containerPath, backingFile); ((IPasswordProtectedItem)folder).CopyFrom(this); return folder; }, ((IPasswordProtectedItem)this).RetryWithCredentialsAsync)); }
开发者ID:files-community,项目名称:Files,代码行数:39,代码来源:ZipStorageFolder.cs
在CreateFolderAsync()方法中,MemoryStream的代码示例类中的SetLength的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的MemoryStream.SetLength方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。