/// <summary> /// Create a new LocalFileHeader /// </summary> /// <param name="fileName"></param> /// <param name="encoding"></param> /// <param name="compressionMethod"></param> /// <param name="deflateOption"></param> /// <param name="streaming">true if in streaming mode</param> /// <returns></returns> internal static ZipIOLocalFileHeader CreateNew(string fileName, Encoding encoding, CompressionMethodEnum compressionMethod, DeflateOptionEnum deflateOption, bool streaming) { //this should be ensured by the higher levels Debug.Assert(Enum.IsDefined(typeof(CompressionMethodEnum), compressionMethod)); Debug.Assert(Enum.IsDefined(typeof(DeflateOptionEnum), deflateOption)); byte[] asciiName = encoding.GetBytes(fileName); if (asciiName.Length > ZipIOBlockManager.MaxFileNameSize) { throw new ArgumentOutOfRangeException("fileName"); } ZipIOLocalFileHeader header = new ZipIOLocalFileHeader(); header._signature = ZipIOLocalFileHeader._signatureConstant; header._compressionMethod = (ushort)compressionMethod; if (streaming) { header._versionNeededToExtract = (UInt16)ZipIOVersionNeededToExtract.Zip64FileFormat; } else { header._versionNeededToExtract = (UInt16)ZipIOBlockManager.CalcVersionNeededToExtractFromCompression( compressionMethod); } if (compressionMethod != CompressionMethodEnum.Stored) { Debug.Assert(deflateOption != DeflateOptionEnum.None); //this should be ensured by the higher levels header.DeflateOption = deflateOption; } if (streaming) { // set bit 3 header.StreamingCreationFlag = true; } header._lastModFileDateTime = ZipIOBlockManager.ToMsDosDateTime(DateTime.Now); header._fileNameLength = (UInt16)asciiName.Length; header._fileName = asciiName; header._extraField = ZipIOExtraField.CreateNew(!streaming /* creating padding if it is not in streaming creation mode */); header._extraFieldLength = header._extraField.Size; //populate frequently used field with user friendly data representations header._stringFileName = fileName; return(header); }
internal static ZipIOCentralDirectoryFileHeader CreateNew(Encoding encoding, ZipIOLocalFileBlock fileBlock) { ZipIOCentralDirectoryFileHeader header = new ZipIOCentralDirectoryFileHeader(encoding); // initialize fields that are not duplicated in the local file block(header) header._fileCommentLength = 0; header._fileComment = null; header._diskNumberStart = 0; header._internalFileAttributes = 0; header._externalFileAttributes = 0; header._versionMadeBy = (ushort)ZipIOVersionNeededToExtract.Zip64FileFormat; header._extraField = ZipIOExtraField.CreateNew(false /* no padding */); // update the rest of the fields based on the local file header header.UpdateFromLocalFileBlock(fileBlock); return(header); }