Beispiel #1
0
        /// <inheritdoc cref="Finish"/>>
        public override async Task FinishAsync(CancellationToken ct)
        {
            using (var ms = new MemoryStream())
            {
                if (entries == null)
                {
                    return;
                }

                if (curEntry != null)
                {
                    await CloseEntryAsync(ct);
                }

                long numEntries  = entries.Count;
                long sizeEntries = 0;

                foreach (var entry in entries)
                {
                    await baseOutputStream_.WriteProcToStreamAsync(ms, s =>
                    {
                        sizeEntries += ZipFormat.WriteEndEntry(s, entry, _stringCodec);
                    }, ct);
                }

                await baseOutputStream_.WriteProcToStreamAsync(ms, s
                                                               => ZipFormat.WriteEndOfCentralDirectory(s, numEntries, sizeEntries, offset, zipComment),
                                                               ct);

                entries = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Finishes the stream.  This will write the central directory at the
        /// end of the zip file and flush the stream.
        /// </summary>
        /// <remarks>
        /// This is automatically called when the stream is closed.
        /// </remarks>
        /// <exception cref="System.IO.IOException">
        /// An I/O error occurs.
        /// </exception>
        /// <exception cref="ZipException">
        /// Comment exceeds the maximum length<br/>
        /// Entry name exceeds the maximum length
        /// </exception>
        public override void Finish()
        {
            if (entries == null)
            {
                return;
            }

            if (curEntry != null)
            {
                CloseEntry();
            }

            long numEntries  = entries.Count;
            long sizeEntries = 0;

            foreach (var entry in entries)
            {
                sizeEntries += ZipFormat.WriteEndEntry(baseOutputStream_, entry, _stringCodec);
            }

            ZipFormat.WriteEndOfCentralDirectory(baseOutputStream_, numEntries, sizeEntries, offset, zipComment);

            entries = null;
        }