Ionic.Zip.ZipFile.AddEntry C# (CSharp) Method

AddEntry() public method

Add an entry, for which the application will provide a stream containing the entry data, on a just-in-time basis.

In cases where the application wishes to open the stream that holds the content for the ZipEntry, on a just-in-time basis, the application can use this method. The application provides an opener delegate that will be called by the DotNetZip library to obtain a readable stream that can be read to get the bytes for the given entry. Typically, this delegate opens a stream. Optionally, the application can provide a closer delegate as well, which will be called by DotNetZip when all bytes have been read from the entry.

These delegates are called from within the scope of the call to ZipFile.Save().

For ZipFile properties including Encryption, , SetCompression, , ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

public AddEntry ( string entryName, OpenDelegate opener, CloseDelegate closer ) : ZipEntry
entryName string the name of the entry to add
opener OpenDelegate /// the delegate that will be invoked by ZipFile.Save() to get the /// readable stream for the given entry. ZipFile.Save() will call /// read on this stream to obtain the data for the entry. This data /// will then be compressed and written to the newly created zip /// file. ///
closer CloseDelegate /// the delegate that will be invoked to close the stream. This may /// be null (Nothing in VB), in which case no call is makde to close /// the stream. ///
return ZipEntry
        public ZipEntry AddEntry(string entryName, OpenDelegate opener, CloseDelegate closer)
        {
            ZipEntry ze = ZipEntry.CreateForJitStreamProvider(entryName, opener, closer);
            ze.SetEntryTimes(DateTime.Now,DateTime.Now,DateTime.Now);
            if (Verbose) StatusMessageTextWriter.WriteLine("adding {0}...", entryName);
            return _InternalAddEntry(ze);
        }

Same methods

ZipFile::AddEntry ( string entryName, Stream stream ) : ZipEntry
ZipFile::AddEntry ( string entryName, WriteDelegate writer ) : ZipEntry
ZipFile::AddEntry ( string entryName, byte byteContent ) : ZipEntry
ZipFile::AddEntry ( string entryName, string content ) : ZipEntry
ZipFile::AddEntry ( string entryName, string content, System encoding ) : ZipEntry

Usage Example

Beispiel #1
1
        public static string CompileNewXAP(HashSet<string> fullsetOfDlls, string shared)
        {
            var tempPath = Path.Combine(shared, Guid.NewGuid() + ".xap");
            using (
                var stream = Assembly.GetExecutingAssembly()
                                     .GetManifestResourceStream("sl_runner.xap.sl-50-xap.xap"))
            using (var baseZip = ZipFile.Read(stream))
            {
                var set = new HashSet<string>();
                var item = baseZip["AppManifest.xaml"];
                var xml = XDocument.Parse(new StreamReader(item.OpenReader()).ReadToEnd());
                using (
                    var zip = new ZipFile()
                    {
                        CompressionLevel = CompressionLevel.Default,
                        CompressionMethod = CompressionMethod.Deflate
                    })
                {
                    zip.AddEntry("AppManifest.xaml", new byte[] { });
                    foreach (var entry in baseZip.Entries)
                    {
                        if (entry.FileName.Contains(".dll"))
                        {
                            using (var memstream = new MemoryStream())
                            {
                                entry.OpenReader().CopyTo(memstream);
                                memstream.Seek(0, SeekOrigin.Begin);
                                zip.AddEntry(entry.FileName, memstream.ToArray());
                                set.Add(Path.GetFileName(entry.FileName));
                            }
                        }
                    }
                    var desc = xml.DescendantNodes().OfType<XElement>();

                    var parts = desc.Single(it => it.Name.LocalName.Contains("Deployment.Parts"));

                    foreach (var dll in fullsetOfDlls)
                    {
                        if (set.Contains(Path.GetFileName(dll)))
                            continue;
                        set.Add(Path.GetFileName(dll));
                        zip.AddFile(dll, "");
                        parts.Add(new XElement(XName.Get("AssemblyPart", "http://schemas.microsoft.com/client/2007/deployment"),
                                               new XAttribute(
                                                   XName.Get("Name", "http://schemas.microsoft.com/winfx/2006/xaml"),
                                                   Path.GetFileNameWithoutExtension(dll)),
                                               new XAttribute("Source", Path.GetFileName(dll))));
                    }
                    using (var memstream = new MemoryStream())
                    {
                        xml.Save(memstream, SaveOptions.OmitDuplicateNamespaces);
                        zip.UpdateEntry("AppManifest.xaml", memstream.ToArray());
                    }
                    zip.Save(tempPath);
                }
            }
            return tempPath;
        }
All Usage Examples Of Ionic.Zip.ZipFile::AddEntry