weltkante/managed-lzma

How to add a folder and add files under the folder?

kingsonchan opened this issue · 3 comments

Now I found this code can compress files into a 7z file:
foreach (var file in directory.EnumerateFiles())
{
using (var fileStream = file.OpenRead())
{
var result = await session.AppendStream(fileStream, true);
metadata.AppendFile(file.Name, result.Length, result.Checksum, file.Attributes, file.CreationTimeUtc, file.LastWriteTimeUtc, file.LastAccessTimeUtc);
}
}

Now what I want is add folders, and files under the folder. How to do that? AppendDirectory? It will broken the 7z file.

Pleas help, thanks a lot.

This is a low level library, you'll have to do it yourself. Basically the 7z format doesn't care about "directories" it just stores a filename with slashes to represent a file in a subfolder. AppendDirectory is for storing empty directories.

Since .NET doesn't have any inbox support for calculating filenames relative to a base directory either, you have to calculate it yourself or find some 3rd party library to determine the relative path you want to store.

With the relative paths I can create folder inside achieve(7z).
but, if achieve already contains folder/directory it fails.

it throws InvalidDataException exception in ArchiveMetadataReader.

Class: ArchiveMetadataReader
Method: ReadSectionDetails()
System.IO.InvalidDataException: 'Found invalid data while decoding.'

Any hints how to resolve this?

@ninad2110 Please provide more details about what you are doing, preferably in a new issue, so I can reproduce the failure.

[edit] I see you have created a similar issue #34 so if thats the same ignore above comment.

Closing this issue since the original question was answered and not followed up on.