Click to See Complete Forum and Search --> : Directory to byte/stream


Fishdawg65
March 13th, 2007, 06:05 PM
I am trying to review GZipStream and the many capabilities. I've gone through the MCTS book's chapter about it but it only goes through files. It only says that you can compress or decompress bytes which can be files or directories....

So, how do I get the bytes of a Directory? or the stream of the Directory?

This may be really simple but for some reason I don't see anything on the net about it.

Thanks for your help.


I'm using .Net 2.0

angedelamort
March 13th, 2007, 11:07 PM
GZipStream Provides methods and properties used to compress and decompress streams. If you want to use that class to compress files/directories, you'll have to do it manually.
i.e.:
1 - Create a files and directories table. An easy example could be a table like that:
directory/file.ext | offset in file | size of compressed data
2 - Open each files and compress them via a stream and add the information in the table.

There is probably free libraries on the net that does that. I don't remember seeing any class in C# that does that automaticly, but I might be wrong. So, in the stream you don't really stream a directory, but you store string to the relative path instead.

I hope it helps.

-edit-
http://www.icsharpcode.net/OpenSource/SharpZipLib/
-edit-

Fishdawg65
March 14th, 2007, 09:13 AM
My question is how to turn a Directory into bytes or into a stream(which can be turned into bytes). I know what GZipStream does and how it works and how to use it with files but I don't know with Directories.

Fishdawg65
March 14th, 2007, 11:23 AM
Maybe I'm looking in the wrong direction here. Can someone explain how to create a Compressed folder in C#? I've found some APIs out there but I'm not sure that is the easiest way.

My thoughts are:
1.Create a compressed folder
2.See if the path given is a directory of a file
2a. if a directory then just create a new directory in the compressed folder.
2b. if a file then just compress the file and place it in the directory structure
3. Recursively call 2 until all files are done.


I think that would would work.

angedelamort
March 14th, 2007, 01:25 PM
Ok, I tought you wanted to create a zip file. Sorry. So you are trying to create a windows compressed folder. I cannot help you on that except that you can probably use System.Management (WMI http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_reference.asp?frame=true)

Your method seems to be good.