/// <inheritdoc/> public byte[] Read(IDataStorerEntry entry) { Validation.NotNull("Entry", entry); ZipReadOnlyStorerEntry zip64Entry = entry as ZipReadOnlyStorerEntry; if (zip64Entry == null) { throw new InvalidEntryException(entry.Path); } byte[] data = null; int count = (int)zip64Entry.Size; if (zip64Entry.CompressionMethod == CompressionMethod.Store) { data = new byte[count]; Buffer.BlockCopy(this.zipFileData, (int)zip64Entry.FileOffset, data, 0, count); } else { data = ZLibUtils.Inflate(this.zipFileData, (int)zip64Entry.FileOffset, (int)zip64Entry.CompressedSize, count); } if (zip64Entry.CRC32 != CRC32.Calculate(data)) { throw new InvalidEntryException(entry.Path); } return(data); }
/// <inheritdoc/> public byte[] Read(IDataStorerEntry entry) { Validation.NotNull("Entry", entry); BinaryReadOnlyStorerEntry binaryEntry = entry as BinaryReadOnlyStorerEntry; if (binaryEntry == null) { throw new InvalidEntryException(entry.Path); } byte[] data = null; int count = (int)binaryEntry.CompressedSize; if (binaryEntry.CompressionMethod == CompressionMethod.Store) { data = new byte[count]; Buffer.BlockCopy(this.binaryData, binaryEntry.FileOffset, data, 0, count); } else { data = ZLibUtils.Inflate(this.binaryData, binaryEntry.FileOffset, binaryEntry.CompressedSize); } return(data); }
public void Inflate_WithOffsetAndCount_Bytes() { byte[] data = new byte[] { 0, 0, 251, 255, 31, 0, 0, 0 }; byte[] expected = new byte[] { 255, 255 }; byte[] inflated = ZLibUtils.Inflate(data, 2, 4); Assert.True(expected.SequenceEqual(inflated)); }
public void Deflate_WithOffsetAndCount_Bytes() { byte[] data = new byte[] { 255, 255, 255, 255 }; byte[] expected = new byte[] { 251, 255, 31, 0 }; byte[] deflated = ZLibUtils.Deflate(data, 1, 2); Assert.True(expected.SequenceEqual(deflated)); }
public void DeflateInflate_WithOffsetAndCount_Bytes() { byte[] data = ArrayUtils.CreateArray((byte)255, 100); Assert.True(data.Skip(10).Take(80).SequenceEqual(ZLibUtils.Inflate(ZLibUtils.Deflate(data, 10, 80)))); }