Ejemplo n.º 1
0
        /// <summary>
        /// Closes the package, optionally leaving the output stream open.
        /// </summary>
        /// <param name="leaveOutputOpen"><c>true</c> to leave the output stream open.</param>
        public void Close(bool leaveOutputOpen)
        {
            if (packageOut != null)
            {
                // Append the terminating entry.

                new PackageEntry(this).Serialize(packageOut);

                // Before we close the package, we need to compute the MD5
                // hash of everything after the header in the output stream
                // and update the hash in the header.

                var header = new PackageHeader();

                packageOut.Position = cbHeader;
                header.Hash         = MD5Hasher.Compute(packageOut, packageOut.Length - cbHeader);

                packageOut.Position = 0;
                header.Seralize(packageOut);

                if (!leaveOutputOpen)
                {
                    packageOut.Close();
                }

                packageOut = null;
            }

            if (packageIn != null)
            {
                packageIn.Close();
                packageIn = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes a package header with a zeroed MD5 hash.  We'll come back
        /// and update this when we compute the hash during <see cref="Close()" />.
        /// </summary>
        private void Create()
        {
            var header = new PackageHeader();

            packageOut.SetLength(0);
            header.Seralize(packageOut);
            cbHeader = (int)packageOut.Position;
        }