本文整理汇总了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);
}
示例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);
}
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}
示例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);
}
}
}