aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs42
1 files changed, 18 insertions, 24 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
index 463e172..67f27b8 100644
--- a/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
+++ b/OpenSim/Region/Environment/Modules/World/Archiver/TarArchiveReader.cs
@@ -52,23 +52,13 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
52 /// </summary> 52 /// </summary>
53 protected char[] m_nullCharArray = new char[] { '\0' }; 53 protected char[] m_nullCharArray = new char[] { '\0' };
54 54
55 public TarArchiveReader(string archivePath)
56 {
57 m_br = new BinaryReader(new FileStream(archivePath, FileMode.Open));
58 }
59
60 /// <summary> 55 /// <summary>
61 /// Are we at the end of the archive? 56 /// Generate a tar reader which reads from the given stream.
62 /// </summary> 57 /// </summary>
63 /// <returns></returns> 58 /// <param name="s"></param>
64 public bool AtEof() 59 public TarArchiveReader(Stream s)
65 { 60 {
66 // If we've reached the end of the archive we'll be in null block territory, which means 61 m_br = new BinaryReader(s);
67 // the next byte will be 0
68 if (m_br.PeekChar() == 0)
69 return true;
70
71 return false;
72 } 62 }
73 63
74 /// <summary> 64 /// <summary>
@@ -79,11 +69,11 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
79 public byte[] ReadEntry(out string filePath) 69 public byte[] ReadEntry(out string filePath)
80 { 70 {
81 filePath = String.Empty; 71 filePath = String.Empty;
82 72
83 if (AtEof())
84 return null;
85
86 TarHeader header = ReadHeader(); 73 TarHeader header = ReadHeader();
74
75 if (null == header)
76 return null;
87 77
88 filePath = header.FilePath; 78 filePath = header.FilePath;
89 byte[] data = m_br.ReadBytes(header.FileSize); 79 byte[] data = m_br.ReadBytes(header.FileSize);
@@ -105,14 +95,18 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
105 95
106 /// <summary> 96 /// <summary>
107 /// Read the next 512 byte chunk of data as a tar header. 97 /// Read the next 512 byte chunk of data as a tar header.
108 /// This method assumes we are not at the end of the archive
109 /// </summary> 98 /// </summary>
110 /// <returns>A tar header struct.</returns> 99 /// <returns>A tar header struct. null if we have reached the end of the archive.</returns>
111 protected TarHeader ReadHeader() 100 protected TarHeader ReadHeader()
112 { 101 {
113 TarHeader tarHeader = new TarHeader();
114
115 byte[] header = m_br.ReadBytes(512); 102 byte[] header = m_br.ReadBytes(512);
103
104 // If we've reached the end of the archive we'll be in null block territory, which means
105 // the next byte will be 0
106 if (header[0] == 0)
107 return null;
108
109 TarHeader tarHeader = new TarHeader();
116 110
117 tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100); 111 tarHeader.FilePath = m_asciiEncoding.GetString(header, 0, 100);
118 tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray); 112 tarHeader.FilePath = tarHeader.FilePath.Trim(m_nullCharArray);
@@ -147,7 +141,7 @@ namespace OpenSim.Region.Environment.Modules.World.Archiver
147 } 141 }
148 } 142 }
149 143
150 public struct TarHeader 144 public class TarHeader
151 { 145 {
152 public string FilePath; 146 public string FilePath;
153 public int FileSize; 147 public int FileSize;