本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipExtraData.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# ZipExtraData.ReadByte方法的具体用法?C# ZipExtraData.ReadByte怎么用?C# ZipExtraData.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipExtraData
的用法示例。
在下文中一共展示了ZipExtraData.ReadByte方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessExtraData
/// <summary>
/// Process extra data fields updating the entry based on the contents.
/// </summary>
/// <param name="localHeader">True if the extra data fields should be handled
/// for a local header, rather than for a central header.
/// </param>
internal void ProcessExtraData(bool localHeader)
{
var extraData = new ZipExtraData(extra);
if (extraData.Find(0x0001))
{
// Version required to extract is ignored here as some archivers dont set it correctly
// in theory it should be version 45 or higher
// The recorded size will change but remember that this is zip64.
forceZip64_ = true;
if (extraData.ValueLength < 4)
{
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if (localHeader || (size == uint.MaxValue))
{
size = (ulong) extraData.ReadLong();
}
if (localHeader || (compressedSize == uint.MaxValue))
{
compressedSize = (ulong) extraData.ReadLong();
}
if (!localHeader && (offset == uint.MaxValue))
{
offset = extraData.ReadLong();
}
// Disk number on which file starts is ignored
}
else
{
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
)
{
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
if (extraData.Find(10))
{
// No room for any tags.
if (extraData.ValueLength < 4)
{
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt(); // Reserved
while (extraData.UnreadCount >= 4)
{
int ntfsTag = extraData.ReadShort();
int ntfsLength = extraData.ReadShort();
if (ntfsTag == 1)
{
if (ntfsLength >= 24)
{
long lastModification = extraData.ReadLong();
long lastAccess = extraData.ReadLong();
long createTime = extraData.ReadLong();
DateTime = DateTime.FromFileTime(lastModification);
}
break;
}
else
{
// An unknown NTFS tag so simply skip it.
extraData.Skip(ntfsLength);
}
}
}
else if (extraData.Find(0x5455))
{
int length = extraData.ValueLength;
int flags = extraData.ReadByte();
// Can include other times but these are ignored. Length of data should
// actually be 1 + 4 * no of bits in flags.
if (((flags & 1) != 0) && (length >= 5))
{
int iTime = extraData.ReadInt();
DateTime = (new DateTime(1970, 1, 1, 0, 0, 0).ToUniversalTime() +
new TimeSpan(0, 0, 0, iTime, 0)).ToLocalTime();
}
}
if (method == CompressionMethod.WinZipAES)
//.........这里部分代码省略.........
示例2: ProcessAESExtraData
// For AES the method in the entry is 99, and the real compression method is in the extradata
//
private void ProcessAESExtraData(ZipExtraData extraData)
{
if (extraData.Find(0x9901)) {
// Set version and flag for Zipfile.CreateAndInitDecryptionStream
versionToExtract = ZipConstants.VERSION_AES; // Ver 5.1 = AES see "Version" getter
// Set StrongEncryption flag for ZipFile.CreateAndInitDecryptionStream
Flags = Flags | (int)GeneralBitFlags.StrongEncryption;
//
// Unpack AES extra data field see http://www.winzip.com/aes_info.htm
int length = extraData.ValueLength; // Data size currently 7
if (length < 7)
throw new ZipException("AES Extra Data Length " + length + " invalid.");
int ver = extraData.ReadShort(); // Version number (1=AE-1 2=AE-2)
int vendorId = extraData.ReadShort(); // 2-character vendor ID 0x4541 = "AE"
int encrStrength = extraData.ReadByte(); // encryption strength 1 = 128 2 = 192 3 = 256
int actualCompress = extraData.ReadShort(); // The actual compression method used to compress the file
_aesVer = ver;
_aesEncryptionStrength = encrStrength;
method = (CompressionMethod)actualCompress;
} else
throw new ZipException("AES Extra Data missing");
}
示例3: Skipping
public void Skipping()
{
ZipExtraData zed = new ZipExtraData(new byte[] { 1, 0, 7, 0, 1, 2, 3, 4, 5, 6, 7 });
Assert.AreEqual(11, zed.Length, "Length should be 11");
Assert.IsTrue(zed.Find(1), "Should find tag 1");
Assert.AreEqual(7, zed.UnreadCount);
Assert.AreEqual(4, zed.CurrentReadIndex);
zed.ReadByte();
Assert.AreEqual(6, zed.UnreadCount);
Assert.AreEqual(5, zed.CurrentReadIndex);
zed.Skip(1);
Assert.AreEqual(5, zed.UnreadCount);
Assert.AreEqual(6, zed.CurrentReadIndex);
zed.Skip(-1);
Assert.AreEqual(6, zed.UnreadCount);
Assert.AreEqual(5, zed.CurrentReadIndex);
zed.Skip(6);
Assert.AreEqual(0, zed.UnreadCount);
Assert.AreEqual(11, zed.CurrentReadIndex);
bool exceptionCaught = false;
try {
zed.Skip(1);
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Should fail to skip past end");
Assert.AreEqual(0, zed.UnreadCount);
Assert.AreEqual(11, zed.CurrentReadIndex);
zed.Skip(-7);
Assert.AreEqual(7, zed.UnreadCount);
Assert.AreEqual(4, zed.CurrentReadIndex);
exceptionCaught=false;
try
{
zed.Skip(-1);
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Should fail to skip before beginning");
}
示例4: UnreadCountValid
public void UnreadCountValid()
{
ZipExtraData zed = new ZipExtraData(new byte[] { 1, 0, 0, 0 });
Assert.AreEqual(4, zed.Length, "Length should be 4");
Assert.IsTrue(zed.Find(1), "Should find tag 1");
Assert.AreEqual(0, zed.UnreadCount);
// seven bytes
zed = new ZipExtraData(new byte[] { 1, 0, 7, 0, 1, 2, 3, 4, 5, 6, 7 });
Assert.IsTrue(zed.Find(1), "Should find tag 1");
for (int i = 0; i < 7; ++i) {
Assert.AreEqual(7 - i, zed.UnreadCount);
zed.ReadByte();
}
zed.ReadByte();
Assert.AreEqual(0, zed.UnreadCount);
}
示例5: BasicOperations
public void BasicOperations()
{
ZipExtraData zed = new ZipExtraData(null);
Assert.AreEqual(0, zed.Length);
zed = new ZipExtraData(new byte[] { 1, 0, 0, 0 });
Assert.AreEqual(4, zed.Length, "A length should be 4");
ZipExtraData zed2 = new ZipExtraData();
Assert.AreEqual(0, zed2.Length);
zed2.AddEntry(1, new byte[] { });
byte[] data = zed.GetEntryData();
for (int i = 0; i < data.Length; ++i) {
Assert.AreEqual(zed2.GetEntryData()[i], data[i]);
}
Assert.AreEqual(4, zed2.Length, "A1 length should be 4");
bool findResult = zed.Find(2);
Assert.IsFalse(findResult, "A - Shouldnt find tag 2");
findResult = zed.Find(1);
Assert.IsTrue(findResult, "A - Should find tag 1");
Assert.AreEqual(0, zed.ValueLength, "A- Length of entry should be 0");
Assert.AreEqual(-1, zed.ReadByte());
Assert.AreEqual(0, zed.GetStreamForTag(1).Length, "A - Length of stream should be 0");
zed = new ZipExtraData(new byte[] { 1, 0, 3, 0, 1, 2, 3 });
Assert.AreEqual(7, zed.Length, "Expected a length of 7");
findResult = zed.Find(1);
Assert.IsTrue(findResult, "B - Should find tag 1");
Assert.AreEqual(3, zed.ValueLength, "B - Length of entry should be 3");
for (int i = 1; i <= 3; ++i) {
Assert.AreEqual(i, zed.ReadByte());
}
Assert.AreEqual(-1, zed.ReadByte());
Stream s = zed.GetStreamForTag(1);
Assert.AreEqual(3, s.Length, "B.1 Stream length should be 3");
for (int i = 1; i <= 3; ++i) {
Assert.AreEqual(i, s.ReadByte());
}
Assert.AreEqual(-1, s.ReadByte());
zed = new ZipExtraData(new byte[] { 1, 0, 3, 0, 1, 2, 3, 2, 0, 1, 0, 56 });
Assert.AreEqual(12, zed.Length, "Expected a length of 12");
findResult = zed.Find(1);
Assert.IsTrue(findResult, "C.1 - Should find tag 1");
Assert.AreEqual(3, zed.ValueLength, "C.1 - Length of entry should be 3");
for (int i = 1; i <= 3; ++i) {
Assert.AreEqual(i, zed.ReadByte());
}
Assert.AreEqual(-1, zed.ReadByte());
findResult = zed.Find(2);
Assert.IsTrue(findResult, "C.2 - Should find tag 2");
Assert.AreEqual(1, zed.ValueLength, "C.2 - Length of entry should be 1");
Assert.AreEqual(56, zed.ReadByte());
Assert.AreEqual(-1, zed.ReadByte());
s = zed.GetStreamForTag(2);
Assert.AreEqual(1, s.Length);
Assert.AreEqual(56, s.ReadByte());
Assert.AreEqual(-1, s.ReadByte());
zed = new ZipExtraData();
zed.AddEntry(7, new byte[] { 33, 44, 55 });
findResult = zed.Find(7);
Assert.IsTrue(findResult, "Add.1 should find new tag");
Assert.AreEqual(3, zed.ValueLength, "Add.1 length should be 3");
Assert.AreEqual(33, zed.ReadByte());
Assert.AreEqual(44, zed.ReadByte());
Assert.AreEqual(55, zed.ReadByte());
Assert.AreEqual(-1, zed.ReadByte());
zed.AddEntry(7, null);
findResult = zed.Find(7);
Assert.IsTrue(findResult, "Add.2 should find new tag");
Assert.AreEqual(0, zed.ValueLength, "Add.2 length should be 0");
zed.StartNewEntry();
zed.AddData(0xae);
zed.AddNewEntry(55);
findResult = zed.Find(55);
Assert.IsTrue(findResult, "Add.3 should find new tag");
Assert.AreEqual(1, zed.ValueLength, "Add.3 length should be 1");
Assert.AreEqual(0xae, zed.ReadByte());
Assert.AreEqual(-1, zed.ReadByte());
zed = new ZipExtraData();
zed.StartNewEntry();
zed.AddLeLong(0);
zed.AddLeLong(-4);
zed.AddLeLong(-1);
zed.AddLeLong(long.MaxValue);
//.........这里部分代码省略.........
示例6: ProcessExtraData
/// <summary>
/// Process extra data fields updating the entry based on the contents.
/// </summary>
/// <param name="localHeader">True if the extra data fields should be handled
/// for a local header, rather than for a central header.
/// </param>
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if ( extraData.Find(0x0001) ) {
if ( (versionToExtract & 0xff) < ZipConstants.VersionZip64 ) {
throw new ZipException("Zip64 Extended information found but version is not valid");
}
// The recorded size will change but remember that this is zip64.
forceZip64_ = true;
if ( extraData.ValueLength < 4 ) {
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if ( localHeader || (size == uint.MaxValue) ) {
size = (ulong)extraData.ReadLong();
}
if ( localHeader || (compressedSize == uint.MaxValue) ) {
compressedSize = (ulong)extraData.ReadLong();
}
}
else {
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
( (size == uint.MaxValue) ||
(compressedSize == uint.MaxValue) )) {
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
/* TODO: Testing for handling of windows extra data
if ( extraData.Find(10) ) {
// No room for any tags.
if ( extraData.ValueLength < 8 ) {
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt(); // Reserved
while ( extraData.UnreadCount >= 4 ) {
int ntfsTag = extraData.ReadShort();
int ntfsLength = extraData.ReadShort();
if ( ntfsTag == 1 ) {
if ( ntfsLength >= 24 ) {
long lastModification = extraData.ReadLong();
long lastAccess = extraData.ReadLong();
long createTime = extraData.ReadLong();
DateTime = System.DateTime.FromFileTime(lastModification);
}
break;
}
else {
// An unknown NTFS tag so simply skip it.
extraData.Skip(ntfsLength);
}
}
}
else
*/
if ( extraData.Find(0x5455) ) {
int length = extraData.ValueLength;
int flags = extraData.ReadByte();
// Can include other times but these are ignored. Length of data should
// actually be 1 + 4 * no of bits in flags.
if ( ((flags & 1) != 0) && (length >= 5) ) {
int iTime = extraData.ReadInt();
DateTime = (new System.DateTime ( 1970, 1, 1, 0, 0, 0 ).ToUniversalTime() +
new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime();
}
}
}
示例7: ProcessExtraData
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if (extraData.Find(1))
{
this.forceZip64_ = true;
if (extraData.ValueLength < 4)
{
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if (localHeader || (this.size == 0xffffffffL))
{
this.size = (ulong) extraData.ReadLong();
}
if (localHeader || (this.compressedSize == 0xffffffffL))
{
this.compressedSize = (ulong) extraData.ReadLong();
}
if (!localHeader && (this.offset == 0xffffffffL))
{
this.offset = extraData.ReadLong();
}
}
else if (((this.versionToExtract & 0xff) >= 0x2d) && ((this.size == 0xffffffffL) || (this.compressedSize == 0xffffffffL)))
{
throw new ZipException("Zip64 Extended information required but is missing.");
}
if (extraData.Find(10))
{
if (extraData.ValueLength < 4)
{
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt();
while (extraData.UnreadCount >= 4)
{
int num = extraData.ReadShort();
int amount = extraData.ReadShort();
if (num == 1)
{
if (amount >= 0x18)
{
long fileTime = extraData.ReadLong();
extraData.ReadLong();
extraData.ReadLong();
this.DateTime = System.DateTime.FromFileTime(fileTime);
}
break;
}
extraData.Skip(amount);
}
}
else if (extraData.Find(0x5455))
{
int valueLength = extraData.ValueLength;
if (((extraData.ReadByte() & 1) != 0) && (valueLength >= 5))
{
int seconds = extraData.ReadInt();
System.DateTime time = new System.DateTime(0x7b2, 1, 1, 0, 0, 0);
this.DateTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime();
}
}
if (this.method == ICSharpCode.SharpZipLib.Zip.CompressionMethod.WinZipAES)
{
this.ProcessAESExtraData(extraData);
}
}
示例8: ProcessAESExtraData
private void ProcessAESExtraData(ZipExtraData extraData)
{
if (!extraData.Find(0x9901))
{
throw new ZipException("AES Extra Data missing");
}
this.versionToExtract = 0x33;
this.Flags |= 0x40;
int valueLength = extraData.ValueLength;
if (valueLength < 7)
{
throw new ZipException("AES Extra Data Length " + valueLength + " invalid.");
}
int num2 = extraData.ReadShort();
extraData.ReadShort();
int num3 = extraData.ReadByte();
int num4 = extraData.ReadShort();
this._aesVer = num2;
this._aesEncryptionStrength = num3;
this.method = (ICSharpCode.SharpZipLib.Zip.CompressionMethod) num4;
}
示例9: ProcessExtraData
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if ( extraData.Find(0x0001) ) {
if ( (versionToExtract & 0xff) < ZipConstants.VersionZip64 ) {
throw new ZipException("Zip64 Extended information found but version is not valid");
}
forceZip64_ = true;
if ( extraData.ValueLength < 4 ) {
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if ( localHeader || (size == uint.MaxValue) ) {
size = (ulong)extraData.ReadLong();
}
if ( localHeader || (compressedSize == uint.MaxValue) ) {
compressedSize = (ulong)extraData.ReadLong();
}
if ( !localHeader && (offset == uint.MaxValue) ) {
offset = extraData.ReadLong();
}
}
else {
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
) {
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
if ( extraData.Find(10) ) {
if ( extraData.ValueLength < 8 ) {
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt();
while ( extraData.UnreadCount >= 4 ) {
int ntfsTag = extraData.ReadShort();
int ntfsLength = extraData.ReadShort();
if ( ntfsTag == 1 ) {
if ( ntfsLength >= 24 ) {
long lastModification = extraData.ReadLong();
long lastAccess = extraData.ReadLong();
long createTime = extraData.ReadLong();
DateTime = System.DateTime.FromFileTime(lastModification);
}
break;
}
else {
extraData.Skip(ntfsLength);
}
}
}
else if ( extraData.Find(0x5455) ) {
int length = extraData.ValueLength;
int flags = extraData.ReadByte();
if ( ((flags & 1) != 0) && (length >= 5) ) {
int iTime = extraData.ReadInt();
DateTime = (new System.DateTime ( 1970, 1, 1, 0, 0, 0 ).ToUniversalTime() +
new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime();
}
}
}