Innovenergy_trunk/csharp/app/OpenVpnCertificatesServer/Utils.cs

39 lines
1.3 KiB
C#

namespace InnovEnergy.OpenVpnCertificatesServer;
using System;
using System.Text;
using ICSharpCode.SharpZipLib.Tar;
public static class Utils
{
public static void WriteFile(this TarOutputStream tar, String fileName, Byte[] contents, Boolean executable = false)
{
var header = new TarHeader
{
Name = fileName.Trim('\\', '/'),
Mode = executable ? 33261 : 33188, // chmod: 100755, 100644
Size = contents.Length,
ModTime = DateTime.UtcNow,
TypeFlag = TarHeader.LF_NORMAL, // normal file
UserName = "",
GroupName = "",
};
var entry = new TarEntry(header);
tar.PutNextEntry(entry);
tar.Write(contents);
tar.CloseEntry();
}
public static void WriteTextFile(this TarOutputStream tar,
String fileName,
String contents,
Encoding? encoding = null,
Boolean executable = false)
{
encoding ??= Encoding.UTF8;
var data = encoding.GetBytes(contents);
tar.WriteFile(fileName, data, executable);
}
}