//------------------------------------------------------
        //
        //  Public Constructors
        //
        //------------------------------------------------------
        // None
        //------------------------------------------------------
        //
        //  Public Properties
        //
        //------------------------------------------------------
        // None
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// Custom Implementation for the GetStream Method
        /// </summary>
        /// <param name="mode">Mode in which the stream should be opened</param>
        /// <param name="access">Access with which the stream should be opened</param>
        /// <returns>Stream Corresponding to this part</returns>
        protected override Stream GetStreamCore(FileMode mode, FileAccess access)
        {
            if (Package.InStreamingCreation)
            {
                // Convert Metro CompressionOption to Zip CompressionMethodEnum.
                CompressionMethodEnum compressionMethod;
                DeflateOptionEnum     deflateOption;
                ZipPackage.GetZipCompressionMethodFromOpcCompressionOption(this.CompressionOption,
                                                                           out compressionMethod, out deflateOption);

                // Mode and access get validated in StreamingZipPartStream().
                return(new StreamingZipPartStream(
                           PackUriHelper.GetStringForPartUri(this.Uri),
                           _zipArchive,
                           compressionMethod, deflateOption,
                           mode, access));
            }
            else if (_zipFileInfo != null)
            {
                // Case of an atomic part.
                return(_zipFileInfo.GetStream(mode, access));
            }
            else
            {
                // Case of an interleaved part.
                Invariant.Assert(_pieces != null);
                return(new InterleavedZipPartStream(this, mode, access));
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method is for custom implementation specific to the file format.
        /// Deletes the part corresponding to the uri specified. Deleting a part that does not
        /// exists is not an error and so we do not throw an exception in that case.
        /// </summary>
        /// <param name="partUri"></param>
        /// <exception cref="ArgumentNullException">If partUri parameter is null</exception>
        /// <exception cref="ArgumentException">If partUri parameter does not conform to the valid partUri syntax</exception>
        protected override void DeletePartCore(Uri partUri)
        {
            //Validating the PartUri - this method will do the argument checking required for uri.
            partUri = PackUriHelper.ValidatePartUri(partUri);

            string          partZipName     = GetZipItemNameFromOpcName(PackUriHelper.GetStringForPartUri(partUri));
            ZipArchiveEntry?zipArchiveEntry = _zipArchive.GetEntry(partZipName);

            // Case of an atomic part.
            zipArchiveEntry?.Delete();

            //Delete the content type for this part if it was specified as an override
            _contentTypeHelper.DeleteContentType((PackUriHelper.ValidatedPartUri)partUri);
        }