public static byte[] ConvertToArray(int flags, string str) { return(ZipStrings.ConvertToArray(flags, str)); }
// Write the local file header // TODO: ZipHelperStream.WriteLocalHeader is not yet used and needs checking for ZipFile and ZipOuptutStream usage private void WriteLocalHeader(ZipEntry entry, EntryPatchData patchData) { CompressionMethod method = entry.CompressionMethod; bool headerInfoAvailable = true; // How to get this? bool patchEntryHeader = false; this.WriteLEInt(ZipConstants.LocalHeaderSignature); this.WriteLEShort(entry.Version); this.WriteLEShort(entry.Flags); this.WriteLEShort((byte)method); this.WriteLEInt((int)entry.DosTime); if (headerInfoAvailable == true) { this.WriteLEInt((int)entry.Crc); if (entry.LocalHeaderRequiresZip64) { this.WriteLEInt(-1); this.WriteLEInt(-1); } else { this.WriteLEInt(entry.IsCrypted ? (int)entry.CompressedSize + ZipConstants.CryptoHeaderSize : (int)entry.CompressedSize); this.WriteLEInt((int)entry.Size); } } else { if (patchData != null) { patchData.CrcPatchOffset = this.stream_.Position; } this.WriteLEInt(0); // Crc if (patchData != null) { patchData.SizePatchOffset = this.stream_.Position; } // For local header both sizes appear in Zip64 Extended Information if (entry.LocalHeaderRequiresZip64 && patchEntryHeader) { this.WriteLEInt(-1); this.WriteLEInt(-1); } else { this.WriteLEInt(0); // Compressed size this.WriteLEInt(0); // Uncompressed size } } byte[] name = ZipStrings.ConvertToArray(entry.Flags, entry.Name); if (name.Length > 0xFFFF) { throw new ZipException("Entry name too long."); } var ed = new ZipExtraData(entry.ExtraData); if (entry.LocalHeaderRequiresZip64 && (headerInfoAvailable || patchEntryHeader)) { ed.StartNewEntry(); if (headerInfoAvailable) { ed.AddLeLong(entry.Size); ed.AddLeLong(entry.CompressedSize); } else { ed.AddLeLong(-1); ed.AddLeLong(-1); } ed.AddNewEntry(1); if (!ed.Find(1)) { throw new ZipException("Internal error cant find extra data"); } if (patchData != null) { patchData.SizePatchOffset = ed.CurrentReadIndex; } } else { ed.Delete(1); } byte[] extra = ed.GetEntryData(); this.WriteLEShort(name.Length); this.WriteLEShort(extra.Length); if (name.Length > 0) { this.stream_.Write(name, 0, name.Length); } if (entry.LocalHeaderRequiresZip64 && patchEntryHeader) { patchData.SizePatchOffset += this.stream_.Position; } if (extra.Length > 0) { this.stream_.Write(extra, 0, extra.Length); } }
public static byte[] ConvertToArray(string str) { return(ZipStrings.ConvertToArray(str)); }