本文整理汇总了C#中System.IO.FileStream.CopyStream方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.CopyStream方法的具体用法?C# FileStream.CopyStream怎么用?C# FileStream.CopyStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了FileStream.CopyStream方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractFiles
private void ExtractFiles(FileStream fs, string extractFolderPath)
{
if (!Directory.Exists(extractFolderPath))
{
Directory.CreateDirectory(extractFolderPath);
}
for (int i = 0; i < directoryNameList.Length; i++)
{
string path = Path.GetFullPath(Path.Combine(extractFolderPath, directoryNameList[i].Name));
if (!path.StartsWith(extractFolderPath)) throw new Exception("Invalid folder path: " + path);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
Stopwatch timer = Stopwatch.StartNew();
for (int i = 0; i < fileNameList.Length; i++)
{
if (timer.ElapsedMilliseconds > 100)
{
bw.ReportProgress(0, new ProgressInfo(i, fileNameList.Length, fileNameList[i].Name));
timer.Reset();
timer.Start();
}
string path = Path.GetFullPath(Path.Combine(extractFolderPath, fileNameList[i].Name));
if (!path.StartsWith(extractFolderPath)) throw new Exception("Invalid file path: " + path);
if (!File.Exists(path))
{
using (FileStream fs2 = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
{
fs.CopyStream(fs2, fileNameList[i].File.Offset, fileNameList[i].File.Size);
}
}
if (AutoConvertPNG && Path.GetExtension(path) == ".tp")
{
using (MemoryStream ms = new MemoryStream())
{
fs.CopyStream(ms, fileNameList[i].File.Offset, fileNameList[i].File.Size);
DataHelpers.ConvertTPtoPNG(ms, path);
}
}
}
bw.ReportProgress(0, new ProgressInfo(fileNameList.Length, fileNameList.Length, null));
}
示例2: Close
public override void Close()
{
long length = stream.Length;
base.Close();
stream.Close();
if (length > 0)
{
//Write data to assembly
using (FileStream tmpIn = new FileStream(assembly.Location, FileMode.Append))
{
tmpIn.Write(signature, 0, signature.Length);
using (FileStream tmpOut = new FileStream(tmpContentFile, FileMode.Open))
{
tmpOut.CopyStream(tmpIn);
tmpOut.Close();
}
tmpIn.Close();
}
}
}
示例3: Close
/// <summary>
/// Close the file appender stream
/// </summary>
/// <param name="writeBack">
/// TRUE if the stream must be write the content of himself to the appender file.
/// <remarks>
/// The file must be closed to this time
/// </remarks>
/// </param>
public virtual void Close(bool writeBack)
{
long length = stream.Length;
stream.Close();
if (length > 0)
{
//Write data to appender file
using (FileStream tmpIn = new FileStream(Filename, FileMode.Append))
{
tmpIn.Write(signature, 0, signature.Length);
using (FileStream tmpOut = new FileStream(tmpContentFile, FileMode.Open))
{
tmpOut.CopyStream(tmpIn);
tmpOut.Close();
}
tmpIn.Close();
}
}
}