29 using System.Collections.Generic;
31 using System.Reflection;
35 namespace OpenSim.Framework.Serialization
47 protected BinaryWriter
m_bw;
51 m_bw =
new BinaryWriter(s);
61 if (!dirName.EndsWith(
"/"))
64 WriteFile(dirName,
new byte[0]);
74 WriteFile(filePath, Util.UTF8NoBomEncoding.GetBytes(data));
84 if (filePath.Length > 100)
85 WriteEntry(
"././@LongLink", Encoding.ASCII.GetBytes(filePath),
'L');
89 if (filePath.EndsWith(
"/"))
98 WriteEntry(filePath, data, fileType);
111 byte[] finalZeroPadding =
new byte[1024];
115 m_bw.Write(finalZeroPadding);
128 oString = Convert.ToString((byte)
'0' + d & 7) + oString;
132 while (oString.Length < padding)
134 oString =
"0" + oString;
137 byte[] oBytes = Encoding.ASCII.GetBytes(oString);
148 protected void WriteEntry(
string filePath, byte[] data,
char fileType)
153 byte[] header =
new byte[512];
156 byte[] nameBytes = Encoding.ASCII.GetBytes(filePath);
157 int nameSize = (nameBytes.Length >= 100) ? 100 : nameBytes.Length;
158 Array.Copy(nameBytes, header, nameSize);
161 byte[] modeBytes = Encoding.ASCII.GetBytes(
"0000777");
162 Array.Copy(modeBytes, 0, header, 100, 7);
165 byte[] ownerIdBytes = Encoding.ASCII.GetBytes(
"0000764");
166 Array.Copy(ownerIdBytes, 0, header, 108, 7);
169 byte[] groupIdBytes = Encoding.ASCII.GetBytes(
"0000764");
170 Array.Copy(groupIdBytes, 0, header, 116, 7);
173 int fileSize = data.Length;
176 byte[] fileSizeBytes = ConvertDecimalToPaddedOctalBytes(fileSize, 11);
178 Array.Copy(fileSizeBytes, 0, header, 124, 11);
181 byte[] lastModTimeBytes = Encoding.ASCII.GetBytes(
"11017037332");
182 Array.Copy(lastModTimeBytes, 0, header, 136, 11);
185 header[156] = Encoding.ASCII.GetBytes(
new char[] { fileType })[0];
187 Array.Copy(Encoding.ASCII.GetBytes(
"0000000"), 0, header, 329, 7);
188 Array.Copy(Encoding.ASCII.GetBytes(
"0000000"), 0, header, 337, 7);
191 Array.Copy(Encoding.ASCII.GetBytes(
" "), 0, header, 148, 8);
194 foreach (byte b
in header)
201 byte[] checkSumBytes = ConvertDecimalToPaddedOctalBytes(checksum, 6);
203 Array.Copy(checkSumBytes, 0, header, 148, 6);
217 if (data.Length % 512 != 0)
219 int paddingRequired = 512 - (data.Length % 512);
223 byte[] padding =
new byte[paddingRequired];
void WriteEntry(string filePath, byte[] data, char fileType)
Write a particular entry
Temporary code to produce a tar archive in tar v7 format
BinaryWriter m_bw
Binary writer for the underlying stream
TarArchiveWriter(Stream s)
static byte[] ConvertDecimalToPaddedOctalBytes(int d, int padding)
void WriteFile(string filePath, string data)
Write a file to the tar archive
void WriteFile(string filePath, byte[] data)
Write a file to the tar archive
void Close()
Finish writing the raw tar archive data to a stream. The stream will be closed on completion...
void WriteDir(string dirName)
Write a directory entry to the tar archive. We can only handle one path level right now! ...