本文整理汇总了C#中ICSharpCode.SharpZipLib.Tar.TarEntry.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# TarEntry.Clone方法的具体用法?C# TarEntry.Clone怎么用?C# TarEntry.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Tar.TarEntry
的用法示例。
在下文中一共展示了TarEntry.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteEntryCore
/// <summary>
/// Write an entry to the archive. This method will call the putNextEntry
/// and then write the contents of the entry, and finally call closeEntry()
/// for entries that are files. For directories, it will call putNextEntry(),
/// and then, if the recurse flag is true, process each entry that is a
/// child of the directory.
/// </summary>
/// <param name="sourceEntry">
/// The TarEntry representing the entry to write to the archive.
/// </param>
/// <param name="recurse">
/// If true, process the children of directory entries.
/// </param>
void WriteEntryCore(TarEntry sourceEntry, bool recurse)
{
string tempFileName = null;
string entryFilename = sourceEntry.File;
TarEntry entry = (TarEntry)sourceEntry.Clone();
if ( applyUserInfoOverrides ) {
entry.GroupId = groupId;
entry.GroupName = groupName;
entry.UserId = userId;
entry.UserName = userName;
}
OnProgressMessageEvent(entry, null);
if (asciiTranslate && !entry.IsDirectory) {
if (!IsBinary(entryFilename)) {
tempFileName = Path.GetTempFileName();
using (StreamReader inStream = File.OpenText(entryFilename)) {
using (Stream outStream = File.Create(tempFileName)) {
while (true) {
string line = inStream.ReadLine();
if (line == null) {
break;
}
byte[] data = Encoding.ASCII.GetBytes(line);
outStream.Write(data, 0, data.Length);
outStream.WriteByte((byte)'\n');
}
outStream.Flush();
}
}
entry.Size = new FileInfo(tempFileName).Length;
entryFilename = tempFileName;
}
}
string newName = null;
if (rootPath != null) {
if (entry.Name.StartsWith(rootPath, StringComparison.OrdinalIgnoreCase)) {
newName = entry.Name.Substring(rootPath.Length + 1 );
}
}
if (pathPrefix != null) {
newName = (newName == null) ? pathPrefix + "/" + entry.Name : pathPrefix + "/" + newName;
}
if (newName != null) {
entry.Name = newName;
}
tarOut.PutNextEntry(entry);
if (entry.IsDirectory) {
if (recurse) {
TarEntry[] list = entry.GetDirectoryEntries();
for (int i = 0; i < list.Length; ++i) {
WriteEntryCore(list[i], recurse);
}
}
}
else {
using (Stream inputStream = File.OpenRead(entryFilename)) {
byte[] localBuffer = new byte[32 * 1024];
while (true) {
int numRead = inputStream.Read(localBuffer, 0, localBuffer.Length);
if (numRead <=0) {
break;
}
tarOut.Write(localBuffer, 0, numRead);
}
}
if ( (tempFileName != null) && (tempFileName.Length > 0) ) {
File.Delete(tempFileName);
}
//.........这里部分代码省略.........
示例2: InternalWriteEntry
/// <summary>
/// Write an entry to the archive. This method will call the putNextEntry
/// and then write the contents of the entry, and finally call closeEntry()
/// for entries that are files. For directories, it will call putNextEntry(),
/// and then, if the recurse flag is true, process each entry that is a
/// child of the directory.
/// </summary>
/// <param name="sourceEntry">
/// The TarEntry representing the entry to write to the archive.
/// </param>
/// <param name="recurse">
/// If true, process the children of directory entries.
/// </param>
void InternalWriteEntry(TarEntry sourceEntry, bool recurse)
{
bool asciiTrans = false;
string tempFileName = null;
string entryFilename = sourceEntry.File;
TarEntry entry = (TarEntry)sourceEntry.Clone();
if ( applyUserInfoOverrides ) {
entry.GroupId = groupId;
entry.GroupName = groupName;
entry.UserId = userId;
entry.UserName = userName;
}
OnProgressMessageEvent(entry, null);
if (this.asciiTranslate && !entry.IsDirectory) {
asciiTrans = !IsBinary(entryFilename);
if (asciiTrans) {
tempFileName = Path.GetTempFileName();
StreamReader inStream = File.OpenText(entryFilename);
Stream outStream = File.Create(tempFileName);
while (true) {
string line = inStream.ReadLine();
if (line == null) {
break;
}
byte[] data = Encoding.ASCII.GetBytes(line);
outStream.Write(data, 0, data.Length);
outStream.WriteByte((byte)'\n');
}
inStream.Close();
outStream.Flush();
outStream.Close();
entry.Size = new FileInfo(tempFileName).Length;
entryFilename = tempFileName;
}
}
string newName = null;
if (this.rootPath != null) {
if (entry.Name.StartsWith(this.rootPath)) {
newName = entry.Name.Substring(this.rootPath.Length + 1 );
}
}
if (this.pathPrefix != null) {
newName = (newName == null) ? this.pathPrefix + "/" + entry.Name : this.pathPrefix + "/" + newName;
}
if (newName != null) {
entry.Name = newName;
}
this.tarOut.PutNextEntry(entry);
if (entry.IsDirectory) {
if (recurse) {
TarEntry[] list = entry.GetDirectoryEntries();
for (int i = 0; i < list.Length; ++i) {
InternalWriteEntry(list[i], recurse);
}
}
} else {
Stream inputStream = File.OpenRead(entryFilename);
int numWritten = 0;
byte[] eBuf = new byte[32 * 1024];
while (true) {
int numRead = inputStream.Read(eBuf, 0, eBuf.Length);
if (numRead <=0) {
break;
}
this.tarOut.Write(eBuf, 0, numRead);
numWritten += numRead;
}
//.........这里部分代码省略.........