本文整理汇总了C#中ZipEntry.IsCompressionMethodSupported方法的典型用法代码示例。如果您正苦于以下问题:C# ZipEntry.IsCompressionMethodSupported方法的具体用法?C# ZipEntry.IsCompressionMethodSupported怎么用?C# ZipEntry.IsCompressionMethodSupported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipEntry
的用法示例。
在下文中一共展示了ZipEntry.IsCompressionMethodSupported方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractEntry
void ExtractEntry(ZipEntry entry)
{
bool doExtraction = entry.IsCompressionMethodSupported();
string targetName = entry.Name;
if ( doExtraction ) {
if ( entry.IsFile ) {
targetName = extractNameTransform_.TransformFile(targetName);
}
else if ( entry.IsDirectory ) {
targetName = extractNameTransform_.TransformDirectory(targetName);
}
doExtraction = !((targetName == null) || (targetName.Length == 0));
}
// TODO: Fire delegate/throw exception were compression method not supported, or name is invalid?
string dirName = null;
if ( doExtraction ) {
if ( entry.IsDirectory ) {
dirName = targetName;
}
else {
dirName = Path.GetDirectoryName(Path.GetFullPath(targetName));
}
}
if ( doExtraction && !Directory.Exists(dirName) ) {
if ( !entry.IsDirectory || CreateEmptyDirectories ) {
try {
Directory.CreateDirectory(dirName);
}
catch (Exception ex) {
doExtraction = false;
if ( events_ != null ) {
if ( entry.IsDirectory ) {
continueRunning_ = events_.OnDirectoryFailure(targetName, ex);
}
else {
continueRunning_ = events_.OnFileFailure(targetName, ex);
}
}
else {
continueRunning_ = false;
throw;
}
}
}
}
if ( doExtraction && entry.IsFile ) {
ExtractFileEntry(entry, targetName);
}
}
示例2: TestLocalHeader
/// <summary>
/// Test a local header against that provided from the central directory
/// </summary>
/// <param name="entry">
/// The entry to test against
/// </param>
/// <param name="tests">The type of <see cref="HeaderTest">tests</see> to carry out.</param>
/// <returns>The offset of the entries data in the file</returns>
long TestLocalHeader(ZipEntry entry, HeaderTest tests)
{
lock(baseStream_)
{
bool testHeader = (tests & HeaderTest.Header) != 0;
bool testData = (tests & HeaderTest.Extract) != 0;
baseStream_.Seek(offsetOfFirstEntry + entry.Offset, SeekOrigin.Begin);
if ((int)ReadLEUint() != ZipConstants.LocalHeaderSignature) {
throw new ZipException(string.Format("Wrong local header signature @{0:X}", offsetOfFirstEntry + entry.Offset));
}
short extractVersion = ( short )ReadLEUshort();
short localFlags = ( short )ReadLEUshort();
short compressionMethod = ( short )ReadLEUshort();
short fileTime = ( short )ReadLEUshort();
short fileDate = ( short )ReadLEUshort();
uint crcValue = ReadLEUint();
long compressedSize = ReadLEUint();
long size = ReadLEUint();
int storedNameLength = ReadLEUshort();
int extraDataLength = ReadLEUshort();
byte[] nameData = new byte[storedNameLength];
StreamUtils.ReadFully(baseStream_, nameData);
byte[] extraData = new byte[extraDataLength];
StreamUtils.ReadFully(baseStream_, extraData);
ZipExtraData localExtraData = new ZipExtraData(extraData);
// Extra data / zip64 checks
if (localExtraData.Find(1))
{
// 2010-03-04 Forum 10512: removed checks for version >= ZipConstants.VersionZip64
// and size or compressedSize = MaxValue, due to rogue creators.
size = localExtraData.ReadLong();
compressedSize = localExtraData.ReadLong();
if ((localFlags & (int)GeneralBitFlags.Descriptor) != 0)
{
// These may be valid if patched later
if ( (size != -1) && (size != entry.Size)) {
throw new ZipException("Size invalid for descriptor");
}
if ((compressedSize != -1) && (compressedSize != entry.CompressedSize)) {
throw new ZipException("Compressed size invalid for descriptor");
}
}
}
else
{
// No zip64 extra data but entry requires it.
if ((extractVersion >= ZipConstants.VersionZip64) &&
(((uint)size == uint.MaxValue) || ((uint)compressedSize == uint.MaxValue)))
{
throw new ZipException("Required Zip64 extended information missing");
}
}
if ( testData ) {
if ( entry.IsFile ) {
if ( !entry.IsCompressionMethodSupported() ) {
throw new ZipException("Compression method not supported");
}
if ( (extractVersion > ZipConstants.VersionMadeBy)
|| ((extractVersion > 20) && (extractVersion < ZipConstants.VersionZip64)) ) {
throw new ZipException(string.Format("Version required to extract this entry not supported ({0})", extractVersion));
}
if ( (localFlags & ( int )(GeneralBitFlags.Patched | GeneralBitFlags.StrongEncryption | GeneralBitFlags.EnhancedCompress | GeneralBitFlags.HeaderMasked)) != 0 ) {
throw new ZipException("The library does not support the zip version required to extract this entry");
}
}
}
if (testHeader)
{
if ((extractVersion <= 63) && // Ignore later versions as we dont know about them..
(extractVersion != 10) &&
(extractVersion != 11) &&
(extractVersion != 20) &&
(extractVersion != 21) &&
(extractVersion != 25) &&
(extractVersion != 27) &&
(extractVersion != 45) &&
(extractVersion != 46) &&
(extractVersion != 50) &&
(extractVersion != 51) &&
//.........这里部分代码省略.........
示例3: ExtractEntry
void ExtractEntry(ZipEntry entry)
{
bool doExtraction = false;
string nameText = entry.Name;
if ( entry.IsFile ) {
// TODO: Translate invalid names allowing extraction still.
doExtraction = NameIsValid(nameText) && entry.IsCompressionMethodSupported();
}
else if ( entry.IsDirectory ) {
doExtraction = NameIsValid(nameText);
}
// TODO: Fire delegate were compression method not supported, or name is invalid?
string dirName = null;
string targetName = null;
if ( doExtraction ) {
// Handle invalid entry names by chopping of path root.
if (Path.IsPathRooted(nameText)) {
string workName = Path.GetPathRoot(nameText);
nameText = nameText.Substring(workName.Length);
}
if ( nameText.Length > 0 )
{
targetName = Path.Combine(targetDirectory_, nameText);
dirName = entry.IsDirectory ? targetName : Path.GetDirectoryName(Path.GetFullPath(targetName));
}
else {
doExtraction = false;
}
}
if ( doExtraction && !Directory.Exists(dirName) ) {
if ( !entry.IsDirectory || CreateEmptyDirectories ) {
try {
Directory.CreateDirectory(dirName);
}
catch (Exception ex) {
doExtraction = false;
if ( events_ != null ) {
continueRunning_ = entry.IsDirectory ? events_.OnDirectoryFailure(targetName, ex) : events_.OnFileFailure(targetName, ex);
}
else {
continueRunning_ = false;
}
}
}
}
if ( doExtraction && entry.IsFile ) {
ExtractFileEntry(entry, targetName);
}
}
示例4: GetNextEntry
//.........这里部分代码省略.........
header == ZipConstants.ArchiveExtraDataSignature ||
header == ZipConstants.Zip64CentralFileHeaderSignature) {
// No more individual entries exist
Close();
return null;
}
// -jr- 07-Dec-2003 Ignore spanning temporary signatures if found
// Spanning signature is same as descriptor signature and is untested as yet.
if ( (header == ZipConstants.SpanningTempSignature) || (header == ZipConstants.SpanningSignature) ) {
header = inputBuffer.ReadLeInt();
}
if (header != ZipConstants.LocalHeaderSignature) {
throw new ZipException("Wrong Local header signature: 0x" + String.Format("{0:X}", header));
}
short versionRequiredToExtract = (short)inputBuffer.ReadLeShort();
flags = inputBuffer.ReadLeShort();
method = inputBuffer.ReadLeShort();
uint dostime = (uint)inputBuffer.ReadLeInt();
int crc2 = inputBuffer.ReadLeInt();
csize = inputBuffer.ReadLeInt();
size = inputBuffer.ReadLeInt();
int nameLen = inputBuffer.ReadLeShort();
int extraLen = inputBuffer.ReadLeShort();
bool isCrypted = (flags & 1) == 1;
byte[] buffer = new byte[nameLen];
inputBuffer.ReadRawBuffer(buffer);
string name = ZipConstants.ConvertToStringExt(flags, buffer);
entry = new ZipEntry(name, versionRequiredToExtract);
entry.Flags = flags;
entry.CompressionMethod = (CompressionMethod)method;
if ((flags & 8) == 0) {
entry.Crc = crc2 & 0xFFFFFFFFL;
entry.Size = size & 0xFFFFFFFFL;
entry.CompressedSize = csize & 0xFFFFFFFFL;
entry.CryptoCheckValue = (byte)((crc2 >> 24) & 0xff);
} else {
// This allows for GNU, WinZip and possibly other archives, the PKZIP spec
// says these values are zero under these circumstances.
if (crc2 != 0) {
entry.Crc = crc2 & 0xFFFFFFFFL;
}
if (size != 0) {
entry.Size = size & 0xFFFFFFFFL;
}
if (csize != 0) {
entry.CompressedSize = csize & 0xFFFFFFFFL;
}
entry.CryptoCheckValue = (byte)((dostime >> 8) & 0xff);
}
entry.DosTime = dostime;
// If local header requires Zip64 is true then the extended header should contain
// both values.
// Handle extra data if present. This can set/alter some fields of the entry.
if (extraLen > 0) {
byte[] extra = new byte[extraLen];
inputBuffer.ReadRawBuffer(extra);
entry.ExtraData = extra;
}
entry.ProcessExtraData(true);
if ( entry.CompressedSize >= 0 ) {
csize = entry.CompressedSize;
}
if ( entry.Size >= 0 ) {
size = entry.Size;
}
if (method == (int)CompressionMethod.Stored && (!isCrypted && csize != size || (isCrypted && csize - ZipConstants.CryptoHeaderSize != size))) {
throw new ZipException("Stored, but compressed != uncompressed");
}
// Determine how to handle reading of data if this is attempted.
if (entry.IsCompressionMethodSupported()) {
internalReader = new ReadDataHandler(InitialRead);
} else {
internalReader = new ReadDataHandler(ReadingNotSupported);
}
return entry;
}