in src/ICSharpCode.SharpZipLib/Tar/TarArchive.cs [807:913]
private void WriteEntryCore(TarEntry sourceEntry, bool recurse)
{
string tempFileName = null;
string entryFilename = sourceEntry.File;
var 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 = PathUtils.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 (!String.IsNullOrEmpty(rootPath))
{
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 (!string.IsNullOrEmpty(tempFileName))
{
File.Delete(tempFileName);
}
tarOut.CloseEntry();
}
}