MemoryStream does not let you look at the length after it has been closed. Overridden here, storing the size when it is closed.
Inheritance: MemoryStream
        // These routines are only to be used by ZipArchive.

        /// <summary>
        /// Used by ZipArchive to write the entry to the archive.
        /// </summary>
        /// <param name="writer">The stream representing the archive to write
        /// the entry to.</param>
        internal void WriteToStream(Stream writer)
        {
            Debug.Assert(!IsReadOnly, "Cannot be read only.");
            Debug.Assert(_positionOfCompressedDataInArchive == 0, "Position must be 0.");   // we don't use this on read-write archives.

            if (_uncompressedData != null)
            {
                if (_uncompressedData.CanWrite)
                {
                    throw new InvalidOperationException("Unclosed writable handle to " + Name + " still exists at Save time");
                }

                // Original to-do statements from the IronPython source:
                // Consider using seeks instead of copying to the compressed data stream.
                // Support not running Deflate but simply skipping

                // Compress the data
                MemoryStream compressedDataStream = new RepairedMemoryStream((int)(_uncompressedData.Length * 5 / 8));
                Stream       compressor           = new DeflateStream(compressedDataStream, CompressionMode.Compress);
                compressor.Write(_uncompressedData.GetBuffer(), 0, (int)_uncompressedData.Length);
                compressor.Close();

                _compressionMethod = CompressionMethod.Deflate;
                _compressedLength  = (int)compressedDataStream.Length;
                _compressedData    = compressedDataStream.GetBuffer();
            }

            Debug.Assert(_compressedData != null, "Must be compressed data.");
            WriteZipFileHeader(writer);                             // Write the header.
            writer.Write(_compressedData, 0, _compressedLength);    // Write the data.
        }
        // These routines are only to be used by ZipArchive.

        /// <summary>
        /// Used by ZipArchive to write the entry to the archive.
        /// </summary>
        /// <param name="writer">The stream representing the archive to write 
        /// the entry to.</param>
        internal void WriteToStream(Stream writer)
        {
            Debug.Assert(!IsReadOnly, "Cannot be read only.");
            Debug.Assert(_positionOfCompressedDataInArchive == 0, "Position must be 0.");   // we don't use this on read-write archives. 

            if (_uncompressedData != null)
            {
                if (_uncompressedData.CanWrite)
                {
                    throw new InvalidOperationException("Unclosed writable handle to " + Name + " still exists at Save time");
                }

                // Original to-do statements from the IronPython source:
                // Consider using seeks instead of copying to the compressed data stream.  
                // Support not running Deflate but simply skipping

                // Compress the data
                MemoryStream compressedDataStream = new RepairedMemoryStream((int)(_uncompressedData.Length * 5 / 8));
                Stream compressor = new DeflateStream(compressedDataStream, CompressionMode.Compress);
                compressor.Write(_uncompressedData.GetBuffer(), 0, (int)_uncompressedData.Length);
                compressor.Close();

                _compressionMethod = CompressionMethod.Deflate;
                _compressedLength = (int)compressedDataStream.Length;
                _compressedData = compressedDataStream.GetBuffer();
            }

            Debug.Assert(_compressedData != null, "Must be compressed data.");
            WriteZipFileHeader(writer);                             // Write the header.
            writer.Write(_compressedData, 0, _compressedLength);      // Write the data. 
        }