Entries don't have FilePaths, they have keys

This commit is contained in:
Adam Hathcock
2013-12-23 12:20:06 +00:00
parent e58ec599f0
commit 66ffc82d41
24 changed files with 45 additions and 43 deletions

View File

@@ -120,7 +120,7 @@ namespace SharpCompress.Test
void archive_EntryExtractionBegin(object sender, ArchiveExtractionEventArgs<IArchiveEntry> e) void archive_EntryExtractionBegin(object sender, ArchiveExtractionEventArgs<IArchiveEntry> e)
{ {
this.entryTotal = e.Item.Size; this.entryTotal = e.Item.Size;
Console.WriteLine("Initializing File Entry Extraction: " + e.Item.FilePath); Console.WriteLine("Initializing File Entry Extraction: " + e.Item.Key);
} }
private long? entryTotal; private long? entryTotal;

View File

@@ -23,7 +23,7 @@ namespace SharpCompress.Test
using (var archive = ArchiveFactory.Open(stream)) using (var archive = ArchiveFactory.Open(stream))
{ {
var entry = archive.Entries.First(); var entry = archive.Entries.First();
entry.WriteToFile(Path.Combine(SCRATCH_FILES_PATH, entry.FilePath)); entry.WriteToFile(Path.Combine(SCRATCH_FILES_PATH, entry.Key));
} }
CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"), CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"),
Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")); Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar"));
@@ -37,7 +37,7 @@ namespace SharpCompress.Test
using (var archive = GZipArchive.Open(stream)) using (var archive = GZipArchive.Open(stream))
{ {
var entry = archive.Entries.First(); var entry = archive.Entries.First();
entry.WriteToFile(Path.Combine(SCRATCH_FILES_PATH, entry.FilePath)); entry.WriteToFile(Path.Combine(SCRATCH_FILES_PATH, entry.Key));
} }
CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"), CompareArchivesByPath(Path.Combine(SCRATCH_FILES_PATH, "Tar.tar"),
Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar")); Path.Combine(TEST_ARCHIVES_PATH, "Tar.tar"));

View File

@@ -135,8 +135,8 @@ namespace SharpCompress.Test
Assert.AreEqual(reader.Entry.CompressionType, CompressionType.Rar); Assert.AreEqual(reader.Entry.CompressionType, CompressionType.Rar);
using (var entryStream = reader.OpenEntryStream()) using (var entryStream = reader.OpenEntryStream())
{ {
string file = Path.GetFileName(reader.Entry.FilePath); string file = Path.GetFileName(reader.Entry.Key);
string folder = Path.GetDirectoryName(reader.Entry.FilePath); string folder = Path.GetDirectoryName(reader.Entry.Key);
string destdir = Path.Combine(SCRATCH_FILES_PATH, folder); string destdir = Path.Combine(SCRATCH_FILES_PATH, folder);
if (!Directory.Exists(destdir)) if (!Directory.Exists(destdir))
{ {
@@ -203,7 +203,7 @@ namespace SharpCompress.Test
{ {
while (reader.MoveToNextEntry()) while (reader.MoveToNextEntry())
{ {
if (reader.Entry.FilePath.Contains("jpg")) if (reader.Entry.Key.Contains("jpg"))
{ {
Assert.AreEqual(reader.Entry.CompressionType, CompressionType.Rar); Assert.AreEqual(reader.Entry.CompressionType, CompressionType.Rar);
reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
@@ -221,7 +221,7 @@ namespace SharpCompress.Test
{ {
while (reader.MoveToNextEntry()) while (reader.MoveToNextEntry())
{ {
if (reader.Entry.FilePath.Contains("jpg")) if (reader.Entry.Key.Contains("jpg"))
{ {
Assert.AreEqual(reader.Entry.CompressionType, CompressionType.Rar); Assert.AreEqual(reader.Entry.CompressionType, CompressionType.Rar);
reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);

View File

@@ -36,7 +36,7 @@ namespace SharpCompress.Test
using (var archive = TarArchive.Open(unmodified)) using (var archive = TarArchive.Open(unmodified))
{ {
Assert.AreEqual(2, archive.Entries.Count); Assert.AreEqual(2, archive.Entries.Count);
Assert.AreEqual(archive.Entries.Last().FilePath, @"very long filename/very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename.jpg"); Assert.AreEqual(archive.Entries.Last().Key, @"very long filename/very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename very long filename.jpg");
} }
} }
@@ -81,7 +81,7 @@ namespace SharpCompress.Test
base.ResetScratch(); base.ResetScratch();
using (var archive = TarArchive.Open(unmodified)) using (var archive = TarArchive.Open(unmodified))
{ {
var entry = archive.Entries.Where(x => x.FilePath.EndsWith("jpg")).Single(); var entry = archive.Entries.Where(x => x.Key.EndsWith("jpg")).Single();
archive.RemoveEntry(entry); archive.RemoveEntry(entry);
archive.SaveTo(scratchPath, CompressionType.None); archive.SaveTo(scratchPath, CompressionType.None);
} }

View File

@@ -46,8 +46,8 @@ namespace SharpCompress.Test
Assert.AreEqual(reader.Entry.CompressionType, CompressionType.BZip2); Assert.AreEqual(reader.Entry.CompressionType, CompressionType.BZip2);
using (var entryStream = reader.OpenEntryStream()) using (var entryStream = reader.OpenEntryStream())
{ {
string file = Path.GetFileName(reader.Entry.FilePath); string file = Path.GetFileName(reader.Entry.Key);
string folder = Path.GetDirectoryName(reader.Entry.FilePath); string folder = Path.GetDirectoryName(reader.Entry.Key);
string destdir = Path.Combine(SCRATCH_FILES_PATH, folder); string destdir = Path.Combine(SCRATCH_FILES_PATH, folder);
if (!Directory.Exists(destdir)) if (!Directory.Exists(destdir))
{ {
@@ -81,7 +81,7 @@ namespace SharpCompress.Test
using (var entryStream = reader.OpenEntryStream()) using (var entryStream = reader.OpenEntryStream())
{ {
entryStream.SkipEntry(); entryStream.SkipEntry();
names.Add(reader.Entry.FilePath); names.Add(reader.Entry.Key);
} }
} }
} }

View File

@@ -144,7 +144,7 @@ namespace SharpCompress.Test
while (archive1.MoveToNextEntry()) while (archive1.MoveToNextEntry())
{ {
Assert.IsTrue(archive2.MoveToNextEntry()); Assert.IsTrue(archive2.MoveToNextEntry());
Assert.AreEqual(archive1.Entry.FilePath, archive2.Entry.FilePath); Assert.AreEqual(archive1.Entry.Key, archive2.Entry.Key);
} }
Assert.IsFalse(archive2.MoveToNextEntry()); Assert.IsFalse(archive2.MoveToNextEntry());
} }

View File

@@ -140,7 +140,7 @@ namespace SharpCompress.Test
base.ResetScratch(); base.ResetScratch();
using (var archive = ZipArchive.Open(unmodified)) using (var archive = ZipArchive.Open(unmodified))
{ {
var entry = archive.Entries.Single(x => x.FilePath.EndsWith("jpg")); var entry = archive.Entries.Single(x => x.Key.EndsWith("jpg"));
archive.RemoveEntry(entry); archive.RemoveEntry(entry);
archive.SaveTo(scratchPath, CompressionType.Deflate); archive.SaveTo(scratchPath, CompressionType.Deflate);
} }
@@ -194,10 +194,10 @@ namespace SharpCompress.Test
using (ZipArchive vfs = (ZipArchive)ArchiveFactory.Open(scratchPath)) using (ZipArchive vfs = (ZipArchive)ArchiveFactory.Open(scratchPath))
{ {
var e = vfs.Entries.First(v => v.FilePath.EndsWith("jpg")); var e = vfs.Entries.First(v => v.Key.EndsWith("jpg"));
vfs.RemoveEntry(e); vfs.RemoveEntry(e);
Assert.IsNull(vfs.Entries.FirstOrDefault(v => v.FilePath.EndsWith("jpg"))); Assert.IsNull(vfs.Entries.FirstOrDefault(v => v.Key.EndsWith("jpg")));
Assert.IsNull(((IArchive)vfs).Entries.FirstOrDefault(v => v.FilePath.EndsWith("jpg"))); Assert.IsNull(((IArchive)vfs).Entries.FirstOrDefault(v => v.Key.EndsWith("jpg")));
} }
} }
@@ -287,8 +287,8 @@ namespace SharpCompress.Test
using (var archive = ZipArchive.Create()) using (var archive = ZipArchive.Create())
{ {
archive.AddAllFromDirectory(SCRATCH_FILES_PATH); archive.AddAllFromDirectory(SCRATCH_FILES_PATH);
archive.RemoveEntry(archive.Entries.Single(x => x.FilePath.EndsWith("jpg", StringComparison.OrdinalIgnoreCase))); archive.RemoveEntry(archive.Entries.Single(x => x.Key.EndsWith("jpg", StringComparison.OrdinalIgnoreCase)));
Assert.IsFalse(archive.Entries.Any(x => x.FilePath.EndsWith("jpg"))); Assert.IsFalse(archive.Entries.Any(x => x.Key.EndsWith("jpg")));
} }
Directory.Delete(SCRATCH_FILES_PATH, true); Directory.Delete(SCRATCH_FILES_PATH, true);
} }

View File

@@ -93,7 +93,7 @@ namespace SharpCompress.Archive
private bool DoesKeyMatchExisting(string key) private bool DoesKeyMatchExisting(string key)
{ {
foreach (var path in Entries.Select(x => x.FilePath)) foreach (var path in Entries.Select(x => x.Key))
{ {
var p = path.Replace('/','\\'); var p = path.Replace('/','\\');
if (p.StartsWith("\\")) if (p.StartsWith("\\"))

View File

@@ -186,7 +186,7 @@ namespace SharpCompress.Archive.GZip
{ {
using (var entryStream = entry.OpenEntryStream()) using (var entryStream = entry.OpenEntryStream())
{ {
writer.Write(entry.FilePath, entryStream, entry.LastModifiedTime); writer.Write(entry.Key, entryStream, entry.LastModifiedTime);
} }
} }
} }

View File

@@ -30,7 +30,7 @@ namespace SharpCompress.Archive.GZip
get { return 0; } get { return 0; }
} }
public override string FilePath public override string Key
{ {
get { return path; } get { return path; }
} }

View File

@@ -21,7 +21,7 @@ namespace SharpCompress.Archive
var streamListener = archiveEntry.Archive as IArchiveExtractionListener; var streamListener = archiveEntry.Archive as IArchiveExtractionListener;
streamListener.EnsureEntriesLoaded(); streamListener.EnsureEntriesLoaded();
streamListener.FireEntryExtractionBegin(archiveEntry); streamListener.FireEntryExtractionBegin(archiveEntry);
streamListener.FireFilePartExtractionBegin(archiveEntry.FilePath, archiveEntry.Size, archiveEntry.CompressedSize); streamListener.FireFilePartExtractionBegin(archiveEntry.Key, archiveEntry.Size, archiveEntry.CompressedSize);
using (Stream s = new ListeningStream(streamListener, archiveEntry.OpenEntryStream())) using (Stream s = new ListeningStream(streamListener, archiveEntry.OpenEntryStream()))
{ {
s.TransferTo(streamToWriteTo); s.TransferTo(streamToWriteTo);
@@ -37,12 +37,12 @@ namespace SharpCompress.Archive
ExtractOptions options = ExtractOptions.Overwrite) ExtractOptions options = ExtractOptions.Overwrite)
{ {
string destinationFileName; string destinationFileName;
string file = Path.GetFileName(entry.FilePath); string file = Path.GetFileName(entry.Key);
if (options.HasFlag(ExtractOptions.ExtractFullPath)) if (options.HasFlag(ExtractOptions.ExtractFullPath))
{ {
string folder = Path.GetDirectoryName(entry.FilePath); string folder = Path.GetDirectoryName(entry.Key);
string destdir = Path.Combine(destinationDirectory, folder); string destdir = Path.Combine(destinationDirectory, folder);
if (!Directory.Exists(destdir)) if (!Directory.Exists(destdir))
{ {

View File

@@ -205,7 +205,7 @@ namespace SharpCompress.Archive.Tar
{ {
using (var entryStream = entry.OpenEntryStream()) using (var entryStream = entry.OpenEntryStream())
{ {
writer.Write(entry.FilePath, entryStream, entry.LastModifiedTime, entry.Size); writer.Write(entry.Key, entryStream, entry.LastModifiedTime, entry.Size);
} }
} }
} }

View File

@@ -30,7 +30,7 @@ namespace SharpCompress.Archive.Tar
get { return 0; } get { return 0; }
} }
public override string FilePath public override string Key
{ {
get { return path; } get { return path; }
} }

View File

@@ -218,7 +218,7 @@ namespace SharpCompress.Archive.Zip
{ {
using (var entryStream = entry.OpenEntryStream()) using (var entryStream = entry.OpenEntryStream())
{ {
writer.Write(entry.FilePath, entryStream, entry.LastModifiedTime, string.Empty); writer.Write(entry.Key, entryStream, entry.LastModifiedTime, string.Empty);
} }
} }
} }

View File

@@ -31,7 +31,7 @@ namespace SharpCompress.Archive.Zip
get { return 0; } get { return 0; }
} }
public override string FilePath public override string Key
{ {
get { return path; } get { return path; }
} }

View File

@@ -5,17 +5,15 @@ namespace SharpCompress.Common
{ {
public abstract class Entry : IEntry public abstract class Entry : IEntry
{ {
internal bool IsSolid { get; set; }
/// <summary> /// <summary>
/// The File's 32 bit CRC Hash /// The File's 32 bit CRC Hash
/// </summary> /// </summary>
public abstract uint Crc { get; } public abstract uint Crc { get; }
/// <summary> /// <summary>
/// The path of the file internal to the Rar Archive. /// The string key of the file internal to the Archive.
/// </summary> /// </summary>
public abstract string FilePath { get; } public abstract string Key { get; }
/// <summary> /// <summary>
/// The compressed file size /// The compressed file size
@@ -62,9 +60,13 @@ namespace SharpCompress.Common
/// </summary> /// </summary>
public abstract bool IsDirectory { get; } public abstract bool IsDirectory { get; }
/// <summary>
/// Entry is split among multiple volumes
/// </summary>
public abstract bool IsSplit { get; } public abstract bool IsSplit { get; }
internal abstract IEnumerable<FilePart> Parts { get; } internal abstract IEnumerable<FilePart> Parts { get; }
internal bool IsSolid { get; set; }
internal virtual void Close() internal virtual void Close()
{ {

View File

@@ -23,7 +23,7 @@ namespace SharpCompress.Common.GZip
get { return 0; } get { return 0; }
} }
public override string FilePath public override string Key
{ {
get { return filePart.FilePartName; } get { return filePart.FilePartName; }
} }

View File

@@ -9,7 +9,7 @@ namespace SharpCompress.Common
long CompressedSize { get; } long CompressedSize { get; }
uint Crc { get; } uint Crc { get; }
DateTime? CreatedTime { get; } DateTime? CreatedTime { get; }
string FilePath { get; } string Key { get; }
bool IsDirectory { get; } bool IsDirectory { get; }
bool IsEncrypted { get; } bool IsEncrypted { get; }
bool IsSplit { get; } bool IsSplit { get; }

View File

@@ -18,7 +18,7 @@ namespace SharpCompress.Common.Rar
/// <summary> /// <summary>
/// The path of the file internal to the Rar Archive. /// The path of the file internal to the Rar Archive.
/// </summary> /// </summary>
public override string FilePath public override string Key
{ {
get { return FileHeader.FileName; } get { return FileHeader.FileName; }
} }
@@ -79,7 +79,7 @@ namespace SharpCompress.Common.Rar
public override string ToString() public override string ToString()
{ {
return string.Format("Entry Path: {0} Compressed Size: {1} Uncompressed Size: {2} CRC: {3}", return string.Format("Entry Path: {0} Compressed Size: {1} Uncompressed Size: {2} CRC: {3}",
FilePath, CompressedSize, Size, Crc); Key, CompressedSize, Size, Crc);
} }
} }
} }

View File

@@ -22,7 +22,7 @@ namespace SharpCompress.Common.SevenZip
get { return FilePart.Header.Crc ?? 0; } get { return FilePart.Header.Crc ?? 0; }
} }
public override string FilePath public override string Key
{ {
get { return FilePart.Header.Name; } get { return FilePart.Header.Name; }
} }

View File

@@ -27,7 +27,7 @@ namespace SharpCompress.Common.Tar
get { return 0; } get { return 0; }
} }
public override string FilePath public override string Key
{ {
get { return filePart.Header.Name; } get { return filePart.Header.Name; }
} }

View File

@@ -58,7 +58,7 @@ namespace SharpCompress.Common.Zip
get { return filePart.Header.Crc; } get { return filePart.Header.Crc; }
} }
public override string FilePath public override string Key
{ {
get { return filePart.Header.Name; } get { return filePart.Header.Name; }
} }

View File

@@ -92,7 +92,7 @@ namespace SharpCompress.Reader
if ((stream == null) || (!stream.CanRead)) if ((stream == null) || (!stream.CanRead))
{ {
throw new MultipartStreamRequiredException("File is split into multiple archives: '" throw new MultipartStreamRequiredException("File is split into multiple archives: '"
+ Entry.FilePath + + Entry.Key +
"'. A new readable stream is required. Use Cancel if it was intended."); "'. A new readable stream is required. Use Cancel if it was intended.");
} }
entriesForCurrentReadStream = GetEntries(stream).GetEnumerator(); entriesForCurrentReadStream = GetEntries(stream).GetEnumerator();

View File

@@ -41,12 +41,12 @@ namespace SharpCompress.Reader
ExtractOptions options = ExtractOptions.Overwrite) ExtractOptions options = ExtractOptions.Overwrite)
{ {
string destinationFileName = string.Empty; string destinationFileName = string.Empty;
string file = Path.GetFileName(reader.Entry.FilePath); string file = Path.GetFileName(reader.Entry.Key);
if (options.HasFlag(ExtractOptions.ExtractFullPath)) if (options.HasFlag(ExtractOptions.ExtractFullPath))
{ {
string folder = Path.GetDirectoryName(reader.Entry.FilePath); string folder = Path.GetDirectoryName(reader.Entry.Key);
string destdir = Path.Combine(destinationDirectory, folder); string destdir = Path.Combine(destinationDirectory, folder);
if (!Directory.Exists(destdir)) if (!Directory.Exists(destdir))
{ {