/// <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; } }
/// <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; }