2 using System
.Collections
;
6 using ICSharpCode
.SharpZipLib
;
7 using ICSharpCode
.SharpZipLib
.Zip
;
14 public class ZipFileObject
: FileObject
{
16 public ZipFileObject (DirectoryObject zip_root
)
20 ArrayList to_be_zipped
;
21 to_be_zipped
= new ArrayList (zip_root
.Children
);
23 foreach (FileSystemObject fso
in to_be_zipped
) {
24 zip_root
.RemoveChild (fso
, null);
25 this.AddChild (fso
, null);
29 override protected string GetChildUri (FileSystemObject children
)
31 // FIXME: What is the uri scheme for zip files?
32 string uri
= this.Uri
+ "#" + children
.Name
;
36 override public string MimeType
{
37 get { return "application/x-zip"; }
40 override public string Extension
{
41 get { return ".zip"; }
44 private void WriteObjectToZip (ZipOutputStream zip_out
,
49 MemoryStream memory
= null;
52 name
= fso
.FullName
.Substring (this.FullName
.Length
+ 1);
53 if (fso
is DirectoryObject
)
57 entry
= new ZipEntry (name
);
58 entry
.DateTime
= fso
.Timestamp
;
60 if (fso
is DirectoryObject
)
63 memory
= new MemoryStream ();
64 ((FileObject
) fso
).AddToStream (memory
, tracker
);
65 entry
.Size
= memory
.Length
;
68 zip_out
.PutNextEntry (entry
);
70 zip_out
.Write (memory
.ToArray (), 0, (int) memory
.Length
);
74 // If this is a directory, write out the children
75 if (fso
is DirectoryObject
)
76 foreach (FileSystemObject child
in fso
.Children
)
77 WriteObjectToZip (zip_out
, child
, tracker
);
80 override public void AddToStream (Stream stream
, EventTracker tracker
)
83 tracker
.ExpectingAdded (this.Uri
);
85 UnclosableStream unclosable
;
86 unclosable
= new UnclosableStream (stream
);
88 ZipOutputStream zip_out
;
89 zip_out
= new ZipOutputStream (unclosable
);
91 foreach (FileSystemObject fso
in Children
)
92 WriteObjectToZip (zip_out
, fso
, tracker
);
97 override protected bool MatchesQueryPart (QueryPart part
)
99 // The only thing that could match is the name, and we check
100 // for that already in FileSystemObject.MatchesQuery.