//------------------------------------------------------ // // Constructors // //------------------------------------------------------ /// <summary> /// Build a System.IO.Stream to create a multi-piece (i.e. interleaved) part. /// Does not require a part, but a proper part name (not a piece name), and a ZipArchive. /// </summary> internal StreamingZipPartStream( string partName, ZipArchive zipArchive, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption, FileMode mode, FileAccess access) { // Right now, only production is supported in streaming mode. if (!( (mode == FileMode.Create || mode == FileMode.CreateNew) && access == FileAccess.Write) ) { throw new NotSupportedException(SR.Get(SRID.OnlyStreamingProductionIsSupported)); } _partName = partName; _archive = zipArchive; _compressionMethod = compressionMethod; _deflateOption = deflateOption; _mode = mode; _access = access; }
/// <summary> /// Constructs a ZipPackagePart for an interleaved part. This is called outside of streaming /// production when an interleaved part is encountered in the package. /// </summary> /// <param name="container"></param> /// <param name="zipArchive"></param> /// <param name="pieces"></param> /// <param name="partUri"></param> /// <param name="compressionOption"></param> /// <param name="contentType"></param> internal ZipPackagePart(ZipPackage container, ZipArchive zipArchive, List<PieceInfo> pieces, PackUriHelper.ValidatedPartUri partUri, string contentType, CompressionOption compressionOption) :base(container, partUri, contentType, compressionOption) { _zipArchive = zipArchive; _pieces = pieces; }
//------------------------------------------------------ // // Public Members // //------------------------------------------------------ // None //------------------------------------------------------ // // Internal Constructors // //------------------------------------------------------ // None //------------------------------------------------------ // // Internal API Methods (although these methods are marked as // Internal, they are part of the internal ZIP IO API surface // //------------------------------------------------------ /// <summary> /// Static constructor File based constructor. all parameteres are obvious. /// This constructor wil open the file in requested mode, and it will not do any futher parsing. /// /// In the case of Create/CreateNew, it will also prebuild in cached in-memory /// EndOfCentralDirectoryRecord (which is a minimal zip file requirement), so that if user /// chooses to close right after he will get a file with just EndOfCentralDirectoryRecord. /// </summary> internal static ZipArchive OpenOnFile(string path, FileMode mode, FileAccess access, FileShare share, bool streaming) { if (mode == FileMode.OpenOrCreate || mode == FileMode.Open) { // for OpenOrCreate cases we need to check whether it is an exisiting file of size 0. // Files of size 0 are onsidered invalid ZipArchives. If we skip this check here, later we wouldn't be able to distinguish // between brand new file being created as a result of OpenOrCreate mode, or old 0 length file being open as a result of // OpenOrCreate mode. FileInfo fileInfo = new FileInfo(path); if (fileInfo.Exists && fileInfo.Length == 0 && (fileInfo.Attributes & FileAttributes.ReparsePoint) == 0) { throw new FileFormatException(SR.Get(SRID.ZipZeroSizeFileIsNotValidArchive)); } } ZipArchive archive = null; FileStream archiveStream = null; // We would like to run initialization after openning stream in try/catch block // so that if anything goes wrong we can close the stream (release file handler) try { archiveStream = new FileStream(path, mode, access, share, 4096, streaming); ValidateModeAccessShareStreaming(archiveStream, mode, access, share, streaming); archive = new ZipArchive(archiveStream, mode, access, streaming, true); } catch { if (archive != null) { archive.Close(); } if(archiveStream != null) { archiveStream.Close(); } throw; } return archive; }
//----------------------------------------------------- // Internal NON API Constructor (this constructor is marked as internal // and isNOT part of the ZIP IO API surface) // It supposed to be called only by the ZipArchive class //------------------------------------------------------ internal ZipFileInfo(ZipArchive zipArchive, ZipIOLocalFileBlock fileBlock) { Debug.Assert((fileBlock != null) && (zipArchive != null)); _fileBlock = fileBlock; _zipArchive = zipArchive; #if DEBUG // validate that date time is legal DateTime dt = LastModFileDateTime; #endif }