本文整理汇总了C#中Ionic.Zip.ZipEntry.MarkAsDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# ZipEntry.MarkAsDirectory方法的具体用法?C# ZipEntry.MarkAsDirectory怎么用?C# ZipEntry.MarkAsDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zip.ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.MarkAsDirectory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadHeader
private static bool ReadHeader(ZipEntry ze, System.Text.Encoding defaultEncoding)
{
int bytesRead = 0;
// change for workitem 8098
ze._RelativeOffsetOfLocalHeader = ze.ArchiveStream.Position;
int signature = Ionic.Zip.SharedUtilities.ReadEntrySignature(ze.ArchiveStream);
bytesRead += 4;
// Return false if this is not a local file header signature.
if (ZipEntry.IsNotValidSig(signature))
{
// Getting "not a ZipEntry signature" is not always wrong or an error.
// This will happen after the last entry in a zipfile. In that case, we
// expect to read :
// a ZipDirEntry signature (if a non-empty zip file) or
// a ZipConstants.EndOfCentralDirectorySignature.
//
// Anything else is a surprise.
ze.ArchiveStream.Seek(-4, SeekOrigin.Current); // unread the signature
// workitem 10178
Ionic.Zip.SharedUtilities.Workaround_Ladybug318918(ze.ArchiveStream);
if (ZipEntry.IsNotValidZipDirEntrySig(signature) && (signature != ZipConstants.EndOfCentralDirectorySignature))
{
throw new BadReadException(String.Format(" ZipEntry::ReadHeader(): Bad signature (0x{0:X8}) at position 0x{1:X8}", signature, ze.ArchiveStream.Position));
}
return false;
}
byte[] block = new byte[26];
int n = ze.ArchiveStream.Read(block, 0, block.Length);
if (n != block.Length) return false;
bytesRead += n;
int i = 0;
ze._VersionNeeded = (Int16)(block[i++] + block[i++] * 256);
ze._BitField = (Int16)(block[i++] + block[i++] * 256);
ze._CompressionMethod_FromZipFile = ze._CompressionMethod = (Int16)(block[i++] + block[i++] * 256);
ze._TimeBlob = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
// transform the time data into something usable (a DateTime)
ze._LastModified = Ionic.Zip.SharedUtilities.PackedToDateTime(ze._TimeBlob);
ze._timestamp |= ZipEntryTimestamp.DOS;
if ((ze._BitField & 0x01) == 0x01)
{
ze._Encryption_FromZipFile = ze._Encryption = EncryptionAlgorithm.PkzipWeak; // this *may* change after processing the Extra field
ze._sourceIsEncrypted = true;
}
// NB: if ((ze._BitField & 0x0008) != 0x0008), then the Compressed, uncompressed and
// CRC values are not true values; the true values will follow the entry data.
// But, regardless of the status of bit 3 in the bitfield, the slots for
// the three amigos may contain marker values for ZIP64. So we must read them.
{
ze._Crc32 = (Int32)(block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256);
ze._CompressedSize = (uint)(block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256);
ze._UncompressedSize = (uint)(block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256);
if ((uint)ze._CompressedSize == 0xFFFFFFFF ||
(uint)ze._UncompressedSize == 0xFFFFFFFF)
ze._InputUsesZip64 = true;
}
Int16 filenameLength = (short)(block[i++] + block[i++] * 256);
Int16 extraFieldLength = (short)(block[i++] + block[i++] * 256);
block = new byte[filenameLength];
n = ze.ArchiveStream.Read(block, 0, block.Length);
bytesRead += n;
// if the UTF8 bit is set for this entry, override the encoding the application requested.
ze._actualEncoding = ((ze._BitField & 0x0800) == 0x0800)
? System.Text.Encoding.UTF8
: defaultEncoding;
// need to use this form of GetString() for .NET CF
ze._FileNameInArchive = ze._actualEncoding.GetString(block, 0, block.Length);
// when creating an entry by reading, the LocalFileName is the same as the FileNameInArchive
// No, on second thought, I think it should be empty (null).
//ze._LocalFileName = ze._FileNameInArchive;
// workitem 6898
if (ze._FileNameInArchive.EndsWith("/")) ze.MarkAsDirectory();
bytesRead += ze.ProcessExtraField(ze.ArchiveStream, extraFieldLength);
ze._LengthOfTrailer = 0;
// workitem 6607 - don't read for directories
// actually get the compressed size and CRC if necessary
if (!ze._FileNameInArchive.EndsWith("/") && (ze._BitField & 0x0008) == 0x0008)
{
// This descriptor exists only if bit 3 of the general
// purpose bit flag is set (see below). It is byte aligned
// and immediately follows the last byte of compressed data,
// as well as any encryption trailer, as with AES.
//.........这里部分代码省略.........
示例2: ReadDirEntry
//.........这里部分代码省略.........
zde._commentLength = (short)(block[i++] + block[i++] * 256);
zde._diskNumber = (UInt32)(block[i++] + block[i++] * 256);
zde._InternalFileAttrs = (short)(block[i++] + block[i++] * 256);
zde._ExternalFileAttrs = block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256;
zde._RelativeOffsetOfLocalHeader = (uint)(block[i++] + block[i++] * 256 + block[i++] * 256 * 256 + block[i++] * 256 * 256 * 256);
// workitem 7801
zde.IsText = ((zde._InternalFileAttrs & 0x01) == 0x01);
block = new byte[zde._filenameLength];
n = s.Read(block, 0, block.Length);
bytesRead += n;
if ((zde._BitField & 0x0800) == 0x0800)
{
// UTF-8 is in use
zde._FileNameInArchive = Ionic.Zip.SharedUtilities.Utf8StringFromBuffer(block);
}
else
{
zde._FileNameInArchive = Ionic.Zip.SharedUtilities.StringFromBuffer(block, expectedEncoding);
}
// Console.WriteLine("\nEntry : {0}", zde._LocalFileName);
// Console.WriteLine(" V Madeby/Needed: 0x{0:X4} / 0x{1:X4}", zde._VersionMadeBy, zde._VersionNeeded);
// Console.WriteLine(" BitField/Compression: 0x{0:X4} / 0x{1:X4}", zde._BitField, zde._CompressionMethod);
// Console.WriteLine(" Lastmod: {0}", zde._LastModified.ToString("u"));
// Console.WriteLine(" CRC: 0x{0:X8}", zde._Crc32);
// Console.WriteLine(" Comp / Uncomp: 0x{0:X8} ({0}) 0x{1:X8} ({1})", zde._CompressedSize, zde._UncompressedSize);
//zde._FileNameInArchive = zde._LocalFileName;
if (zde.AttributesIndicateDirectory) zde.MarkAsDirectory(); // may append a slash to filename if nec.
// workitem 6898
else if (zde._FileNameInArchive.EndsWith("/")) zde.MarkAsDirectory();
zde._CompressedFileDataSize = zde._CompressedSize;
if ((zde._BitField & 0x01) == 0x01)
{
zde._Encryption_FromZipFile = zde._Encryption = EncryptionAlgorithm.PkzipWeak; // this may change after processing the Extra field
zde._sourceIsEncrypted = true;
}
if (zde._extraFieldLength > 0)
{
zde._InputUsesZip64 = (zde._CompressedSize == 0xFFFFFFFF ||
zde._UncompressedSize == 0xFFFFFFFF ||
zde._RelativeOffsetOfLocalHeader == 0xFFFFFFFF);
// Console.WriteLine(" Input uses Z64?: {0}", zde._InputUsesZip64);
bytesRead += zde.ProcessExtraField(s, zde._extraFieldLength);
zde._CompressedFileDataSize = zde._CompressedSize;
}
// we've processed the extra field, so we know the encryption method is set now.
if (zde._Encryption == EncryptionAlgorithm.PkzipWeak)
{
// the "encryption header" of 12 bytes precedes the file data
zde._CompressedFileDataSize -= 12;
}
#if AESCRYPTO
else if (zde.Encryption == EncryptionAlgorithm.WinZipAes128 ||
zde.Encryption == EncryptionAlgorithm.WinZipAes256)
{
示例3: PutNextEntry
/// <summary>
/// Specify the name of the next entry that will be written to the zip file.
/// </summary>
///
/// <remarks>
/// <para>
/// Call this method just before calling <see cref="Write(byte[], int, int)"/>, to
/// specify the name of the entry that the next set of bytes written to
/// the <c>ZipOutputStream</c> belongs to. All subsequent calls to <c>Write</c>,
/// until the next call to <c>PutNextEntry</c>,
/// will be inserted into the named entry in the zip file.
/// </para>
///
/// <para>
/// If the <paramref name="entryName"/> used in <c>PutNextEntry()</c> ends in
/// a slash, then the entry added is marked as a directory. Because directory
/// entries do not contain data, a call to <c>Write()</c>, before an
/// intervening additional call to <c>PutNextEntry()</c>, will throw an
/// exception.
/// </para>
///
/// <para>
/// If you don't call <c>Write()</c> between two calls to
/// <c>PutNextEntry()</c>, the first entry is inserted into the zip file as a
/// file of zero size. This may be what you want.
/// </para>
///
/// <para>
/// Because <c>PutNextEntry()</c> closes out the prior entry, if any, this
/// method may throw if there is a problem with the prior entry.
/// </para>
///
/// <para>
/// This method returns the <c>ZipEntry</c>. You can modify public properties
/// on the <c>ZipEntry</c>, such as <see cref="ZipEntry.Encryption"/>, <see
/// cref="ZipEntry.Password"/>, and so on, until the first call to
/// <c>ZipOutputStream.Write()</c>, or until the next call to
/// <c>PutNextEntry()</c>. If you modify the <c>ZipEntry</c> <em>after</em>
/// having called <c>Write()</c>, you may get a runtime exception, or you may
/// silently get an invalid zip archive.
/// </para>
///
/// </remarks>
///
/// <example>
///
/// This example shows how to create a zip file, using the
/// <c>ZipOutputStream</c> class.
///
/// <code>
/// private void Zipup()
/// {
/// using (FileStream fs raw = File.Open(_outputFileName, FileMode.Create, FileAccess.ReadWrite ))
/// {
/// using (var output= new ZipOutputStream(fs))
/// {
/// output.Password = "VerySecret!";
/// output.Encryption = EncryptionAlgorithm.WinZipAes256;
/// output.PutNextEntry("entry1.txt");
/// byte[] buffer= System.Text.Encoding.ASCII.GetBytes("This is the content for entry #1.");
/// output.Write(buffer,0,buffer.Length);
/// output.PutNextEntry("entry2.txt"); // this will be zero length
/// output.PutNextEntry("entry3.txt");
/// buffer= System.Text.Encoding.ASCII.GetBytes("This is the content for entry #3.");
/// output.Write(buffer,0,buffer.Length);
/// }
/// }
/// }
/// </code>
/// </example>
///
/// <param name="entryName">
/// The name of the entry to be added, including any path to be used
/// within the zip file.
/// </param>
///
/// <returns>
/// The ZipEntry created.
/// </returns>
///
public ZipEntry PutNextEntry(String entryName)
{
if (_disposed)
{
_exceptionPending = true;
throw new System.InvalidOperationException("The stream has been closed.");
}
_FinishCurrentEntry();
_currentEntry = ZipEntry.CreateForZipOutputStream(entryName);
_currentEntry._container = new ZipContainer(this);
_currentEntry._BitField |= 0x0008; // workitem 8932
_currentEntry.SetEntryTimes(DateTime.Now, DateTime.Now, DateTime.Now);
_currentEntry.CompressionLevel = CompressionLevel;
_currentEntry.Encryption = Encryption;
_currentEntry.Password = _password;
if (entryName.EndsWith("/")) _currentEntry.MarkAsDirectory();
_currentEntry.EmitTimesInWindowsFormatWhenSaving = ((_timestamp & ZipEntryTimestamp.Windows) != 0);
//.........这里部分代码省略.........