ArchiveEntry.Key is dependent on the archivetype #150

Closed
opened 2026-01-29 22:07:25 +00:00 by claunia · 4 comments
Owner

Originally created by @evpxregu on GitHub (Dec 10, 2016).

Originally assigned to: @adamhathcock on GitHub.

Hi,

When I run the following code the directory seperator in the IArchiveEntry.Key is different for different archive types.

var _archive = new ArchiveFactory.Open(file, options);
foreach (var entry in _archive.Entries)
{
    Console.WriteLine(entry.Key);
}

Output for a .rar file:

subfolder\folder in subfolder\test fiel in sub-sub-subfolder.txt
subfolder\test fiel in sub-subfolder.txt
subfolder\folder in subfolder

output for a .zip file

subfolder/folder in subfolder/test fiel in sub-sub-subfolder.txt
subfolder/test fiel in sub-subfolder.txt
subfolder/folder in subfolder 0

Is this by design or a bug? Both archives are created on the same computer.

Originally created by @evpxregu on GitHub (Dec 10, 2016). Originally assigned to: @adamhathcock on GitHub. Hi, When I run the following code the directory seperator in the IArchiveEntry.Key is different for different archive types. ``` var _archive = new ArchiveFactory.Open(file, options); foreach (var entry in _archive.Entries) { Console.WriteLine(entry.Key); } ``` Output for a .rar file: > subfolder\folder in subfolder\test fiel in sub-sub-subfolder.txt > subfolder\test fiel in sub-subfolder.txt > subfolder\folder in subfolder output for a .zip file > subfolder/folder in subfolder/test fiel in sub-sub-subfolder.txt > subfolder/test fiel in sub-subfolder.txt > subfolder/folder in subfolder 0 Is this by design or a bug? Both archives are created on the same computer.
claunia added the bug label 2026-01-29 22:07:25 +00:00
Author
Owner

@adamhathcock commented on GitHub (Dec 10, 2016):

It seems likely there's a bug in creating where I hardcoded the path separator. I'm not sure I should use he OS's separator or always pick one.

The archive specs may have one specifically. I'll have to look it up.

@adamhathcock commented on GitHub (Dec 10, 2016): It seems likely there's a bug in creating where I hardcoded the path separator. I'm not sure I should use he OS's separator or always pick one. The archive specs may have one specifically. I'll have to look it up.
Author
Owner

@leezer3 commented on GitHub (Dec 11, 2016):

https://github.com/adamhathcock/sharpcompress/pull/114

You've got a hardcoded path separator issue in your RAR extractor
https://github.com/adamhathcock/sharpcompress/blob/master/src/SharpCompress/Common/Rar/Headers/FileHeader.cs#L168

Dumping the switch statement in favour of this ought to fix it:

if (Path.DirectorySeparatorChar == '/')
{
	return path.Replace('\\', '/');
}
else if (Path.DirectorySeparatorChar == '\\')
{
	return path.Replace('/', '\\');
}

RAR always wants a \ as it's path separator.
Note:
Haven't tested this on create, hence why I'm not running up a pull request, but I don't see any reason for it to fail.

@leezer3 commented on GitHub (Dec 11, 2016): https://github.com/adamhathcock/sharpcompress/pull/114 You've got a hardcoded path separator issue in your RAR extractor https://github.com/adamhathcock/sharpcompress/blob/master/src/SharpCompress/Common/Rar/Headers/FileHeader.cs#L168 Dumping the switch statement in favour of this ought to fix it: ``` if (Path.DirectorySeparatorChar == '/') { return path.Replace('\\', '/'); } else if (Path.DirectorySeparatorChar == '\\') { return path.Replace('/', '\\'); } ``` RAR always wants a **\\** as it's path separator. Note: Haven't tested this on create, hence why I'm not running up a pull request, but I don't see any reason for it to fail.
Author
Owner

@adamhathcock commented on GitHub (Dec 12, 2016):

I'll look into this soon. I was thinking archive formats want something specific and SharpCompress will have to adjust it one top of the formats like you're saying.

@adamhathcock commented on GitHub (Dec 12, 2016): I'll look into this soon. I was thinking archive formats want something specific and SharpCompress will have to adjust it one top of the formats like you're saying.
Author
Owner

@adamhathcock commented on GitHub (May 22, 2017):

Finally made a PR for this https://github.com/adamhathcock/sharpcompress/pull/238

@adamhathcock commented on GitHub (May 22, 2017): Finally made a PR for this https://github.com/adamhathcock/sharpcompress/pull/238
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#150