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


C# BufferedStream.CopyTo方法代码示例

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


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

示例1: AddFile

        public void AddFile(DeduplicatorState state, FileInfo sourceFile, string destinationPath)
        {
            if (state.DestinationToFileHash.ContainsKey(destinationPath))
            {
                // File has already been added.
                return;
            }

            // Read the source file.
            var memory = new MemoryStream();
            using (var stream = new BufferedStream(new FileStream(sourceFile.FullName, FileMode.Open, FileAccess.Read, FileShare.None), 1200000))
            {
                stream.CopyTo(memory);
            }

            // Hash the memory stream.
            var sha1 = new SHA1Managed();
            memory.Seek(0, SeekOrigin.Begin);
            var hashBytes = sha1.ComputeHash(memory);
            var hashString = BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
            memory.Seek(0, SeekOrigin.Begin);

            // Add to the file hash -> source map if not already present.
            if (!state.FileHashToSource.ContainsKey(hashString))
            {
                state.FileHashToSource.Add(hashString, memory);
            }
            else
            {
                memory.Dispose();
            }

            state.DestinationToFileHash.Add(destinationPath, hashString);
        }
开发者ID:marler8997,项目名称:Protobuild,代码行数:34,代码来源:Deduplicator.cs

示例2: SendFile

        private static void SendFile(string path, HttpListenerResponse target)
        {
            target.ContentLength64 = new FileInfo(path).Length;

            using (var file = new BufferedStream(File.OpenRead(path)))
            using (var output = target.OutputStream) {
                file.CopyTo(output);
            }
        }
开发者ID:Troposphir,项目名称:AtmoLauncher,代码行数:9,代码来源:GetFile.cs

示例3: Load

        public MemoryStream Load(string path)
        {
            var result = new MemoryStream();

            using (var fileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            using (var bufferedStream = new BufferedStream(fileStream))
            {
                bufferedStream.CopyTo(result);
            }

            return result;
        }
开发者ID:Torevild,项目名称:ImageProcessingSuit,代码行数:12,代码来源:FileSystemLoader.cs

示例4: Decompress

        public static byte[] Decompress(byte[] inputData)
        {
            if (inputData == null)
                throw new ArgumentNullException("inputData");

            using (var compressedMs = new MemoryStream(inputData))
            {
                using (var decompressedMs = MiNetServer.MemoryStreamManager.GetStream())
                {
                    using (var gzs = new BufferedStream(new GZipStream(compressedMs, CompressionMode.Decompress), 2*4096))
                    {
                        gzs.CopyTo(decompressedMs);
                    }
                    return decompressedMs.ToArray();
                }
            }
        }
开发者ID:CRBairdUSA,项目名称:MiNET,代码行数:17,代码来源:Compression.cs

示例5: Decompress

        public static byte[] Decompress(byte[] inputData)
        {
            if (inputData == null)
                throw new ArgumentNullException("inputData must be non-null");

            using (var compressedMs = new MemoryStream(inputData))
            {
                using (var decompressedMs = new MemoryStream())
                {
                    using (var gzs = new BufferedStream(new GZipStream(compressedMs,
                     CompressionMode.Decompress), BUFFER_SIZE))
                    {
                        gzs.CopyTo(decompressedMs);
                    }
                    return decompressedMs.ToArray();
                }
            }
        }
开发者ID:DacoTaco,项目名称:AudioStreaming,代码行数:18,代码来源:Compressor.cs

示例6: GetZippedPayload

        /// <summary>
        /// Creates a zip archive containing specific files from the application folder
        /// </summary>
        /// <param name="appPath">The path to the application folder</param>
        /// <param name="files">The files that will be added to the archive.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>An open stream of the zip file</returns>
        public async Task<System.IO.Stream> GetZippedPayload(string appPath, IEnumerable<string> files, System.Threading.CancellationToken cancellationToken)
        {
            string zipFile = Path.Combine(Path.GetTempPath(), "payload.zip");

            //// If no files need to be uploaded we create a dummy file
            using (var enumerator = files.GetEnumerator())
            {
                //// equivalent to ( files.Count == 0 ) 
                if (enumerator.MoveNext() == false)
                {
                    string emptyFile = "_empty_";
                    File.WriteAllText(Path.Combine(appPath, emptyFile), Guid.NewGuid().ToString());
                    files = new string[] { emptyFile };
                }
            }

            using (Stream zipStream = new FileStream(zipFile, FileMode.Create))
            {
                using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create))
                {
                    foreach (string file in files)
                    {
                        if (file.Length > 0)
                        {
                            await Task.Factory.StartNew(new Action(() =>
                            {
                                using (FileStream fs = new FileStream(Path.Combine(appPath, file), FileMode.Open))
                                {
                                    using (BufferedStream bs = new BufferedStream(fs))
                                    {
                                        ZipArchiveEntry entry = archive.CreateEntry(file, CompressionLevel.Optimal);
                                        using (BufferedStream writer = new BufferedStream(entry.Open()))
                                        {
                                            bs.CopyTo(writer);
                                        }
                                    }
                                }
                            }));
                        }
                    }
                }
            }

            Stream fileStream = new FileStream(zipFile, FileMode.Open);
            return fileStream;
        }
开发者ID:adasescu,项目名称:cf-dotnet-sdk-1,代码行数:53,代码来源:AppPushTools.cs

示例7: toolStripItemPush_Click

 private void toolStripItemPush_Click(object sender, EventArgs e)
 {
     if (!PromptSave())
         return;
     if (localFileName == null || localFileName == "")
     {
         MessageBox.Show(this, "Unable to upload: No file open", "Unable to upload",
             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return;
     }
     using (var fileStream = new FileStream(localFileName, FileMode.Open, FileAccess.Read))
     using (var bufferedStream = new BufferedStream(fileStream))
     {
         try
         {
             using (var ftpStream = ftpClient.OpenWrite(this.remoteFileName, FtpDataType.ASCII))
             {
                 bufferedStream.CopyTo(ftpStream);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(this, "FTP Error: " + ex.Message, "FTP Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
开发者ID:Team2122,项目名称:SpudConf,代码行数:26,代码来源:SpudConf.cs


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