ICSharpCode.SharpZipLib.Zip.ZipHelperStream - Coverage Report

# Summary

Class: | ICSharpCode.SharpZipLib.Zip.ZipHelperStream
Assembly: | ICSharpCode.SharpZipLib
File(s): | C:\Users\Neil\Documents\Visual Studio 2015\Projects\icsharpcode\SZL_master\ICSharpCode.SharpZipLib\Zip\ZipHelperStream.cs
Covered lines: | 106
Uncovered lines: | 88
Coverable lines: | 194
Total lines: | 560
Line coverage: | 54.6%
Branch coverage: | 42.8%

# Metrics

Method | Cyclomatic Complexity | Sequence Coverage | Branch Coverage
--- | --- | --- | ---
.ctor(...) | 1 | 0 | 0
.ctor(...) | 1 | 100 | 100
Flush() | 1 | 0 | 0
Seek(...) | 1 | 100 | 100
SetLength(...) | 1 | 100 | 100
Read(...) | 1 | 100 | 100
Write(...) | 1 | 100 | 100
Close() | 3 | 100 | 100
WriteLocalHeader(...) | 16 | 0 | 0
LocateBlockWithSignature(...) | 4 | 88.89 | 85.71
WriteZip64EndOfCentralDirectory(...) | 1 | 100 | 100
WriteEndOfCentralDirectory(...) | 11 | 80.77 | 73.68
ReadLEShort() | 3 | 71.43 | 60
ReadLEInt() | 1 | 100 | 100
ReadLELong() | 1 | 100 | 100
WriteLEShort(...) | 1 | 100 | 100
WriteLEUshort(...) | 1 | 100 | 100
WriteLEInt(...) | 1 | 100 | 100
WriteLEUint(...) | 1 | 0 | 0
WriteLELong(...) | 1 | 100 | 100
WriteLEUlong(...) | 1 | 0 | 0
WriteDataDescriptor(...) | 4 | 68.75 | 57.14
ReadDataDescriptor(...) | 3 | 90.91 | 80

# File(s)

## C:\Users\Neil\Documents\Visual Studio 2015\Projects\icsharpcode\SZL_master\ICSharpCode.SharpZipLib\Zip\ZipHelperStream.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.IO;`
|  | `3` |  | `using System.Text;`
|  | `4` |  | ``
|  | `5` |  | `namespace ICSharpCode.SharpZipLib.Zip`
|  | `6` |  | `{`
|  | `7` |  | `/// <summary>`
|  | `8` |  | `/// Holds data pertinent to a data descriptor.`
|  | `9` |  | `/// </summary>`
|  | `10` |  | `public class DescriptorData`
|  | `11` |  | `{`
|  | `12` |  | `/// <summary>`
|  | `13` |  | `/// Get /set the compressed size of data.`
|  | `14` |  | `/// </summary>`
|  | `15` |  | `public long CompressedSize {`
|  | `16` |  | `get { return compressedSize; }`
|  | `17` |  | `set { compressedSize = value; }`
|  | `18` |  | `}`
|  | `19` |  | ``
|  | `20` |  | `/// <summary>`
|  | `21` |  | `/// Get / set the uncompressed size of data`
|  | `22` |  | `/// </summary>`
|  | `23` |  | `public long Size {`
|  | `24` |  | `get { return size; }`
|  | `25` |  | `set { size = value; }`
|  | `26` |  | `}`
|  | `27` |  | ``
|  | `28` |  | `/// <summary>`
|  | `29` |  | `/// Get /set the crc value.`
|  | `30` |  | `/// </summary>`
|  | `31` |  | `public long Crc {`
|  | `32` |  | `get { return crc; }`
|  | `33` |  | `set { crc = (value & 0xffffffff); }`
|  | `34` |  | `}`
|  | `35` |  | ``
|  | `36` |  | `#region Instance Fields`
|  | `37` |  | `long size;`
|  | `38` |  | `long compressedSize;`
|  | `39` |  | `long crc;`
|  | `40` |  | `#endregion`
|  | `41` |  | `}`
|  | `42` |  | ``
|  | `43` |  | `class EntryPatchData`
|  | `44` |  | `{`
|  | `45` |  | `public long SizePatchOffset {`
|  | `46` |  | `get { return sizePatchOffset_; }`
|  | `47` |  | `set { sizePatchOffset_ = value; }`
|  | `48` |  | `}`
|  | `49` |  | ``
|  | `50` |  | `public long CrcPatchOffset {`
|  | `51` |  | `get { return crcPatchOffset_; }`
|  | `52` |  | `set { crcPatchOffset_ = value; }`
|  | `53` |  | `}`
|  | `54` |  | ``
|  | `55` |  | `#region Instance Fields`
|  | `56` |  | `long sizePatchOffset_;`
|  | `57` |  | `long crcPatchOffset_;`
|  | `58` |  | `#endregion`
|  | `59` |  | `}`
|  | `60` |  | ``
|  | `61` |  | `/// <summary>`
|  | `62` |  | `/// This class assists with writing/reading from Zip files.`
|  | `63` |  | `/// </summary>`
|  | `64` |  | `internal class ZipHelperStream : Stream`
|  | `65` |  | `{`
|  | `66` |  | `#region Constructors`
|  | `67` |  | `/// <summary>`
|  | `68` |  | `/// Initialise an instance of this class.`
|  | `69` |  | `/// </summary>`
|  | `70` |  | `/// <param name="name">The name of the file to open.</param>`
| 0 | `71` |  | `public ZipHelperStream(string name)`
|  | `72` |  | `{`
| 0 | `73` |  | `stream_ = new FileStream(name, FileMode.Open, FileAccess.ReadWrite);`
| 0 | `74` |  | `isOwner_ = true;`
| 0 | `75` |  | `}`
|  | `76` |  | ``
|  | `77` |  | `/// <summary>`
|  | `78` |  | `/// Initialise a new instance of <see cref="ZipHelperStream"/>.`
|  | `79` |  | `/// </summary>`
|  | `80` |  | `/// <param name="stream">The stream to use.</param>`
| 272 | `81` |  | `public ZipHelperStream(Stream stream)`
|  | `82` |  | `{`
| 272 | `83` |  | `stream_ = stream;`
| 272 | `84` |  | `}`
|  | `85` |  | `#endregion`
|  | `86` |  | ``
|  | `87` |  | `/// <summary>`
|  | `88` |  | `/// Get / set a value indicating wether the the underlying stream is owned or not.`
|  | `89` |  | `/// </summary>`
|  | `90` |  | `/// <remarks>If the stream is owned it is closed when this instance is closed.</remarks>`
|  | `91` |  | `public bool IsStreamOwner {`
| 0 | `92` |  | `get { return isOwner_; }`
| 8 | `93` |  | `set { isOwner_ = value; }`
|  | `94` |  | `}`
|  | `95` |  | ``
|  | `96` |  | `#region Base Stream Methods`
|  | `97` |  | `public override bool CanRead {`
| 0 | `98` |  | `get { return stream_.CanRead; }`
|  | `99` |  | `}`
|  | `100` |  | ``
|  | `101` |  | `public override bool CanSeek {`
| 0 | `102` |  | `get { return stream_.CanSeek; }`
|  | `103` |  | `}`
|  | `104` |  | ``
|  | `105` |  | `public override bool CanTimeout {`
| 0 | `106` |  | `get { return stream_.CanTimeout; }`
|  | `107` |  | `}`
|  | `108` |  | ``
|  | `109` |  | `public override long Length {`
| 1 | `110` |  | `get { return stream_.Length; }`
|  | `111` |  | `}`
|  | `112` |  | ``
|  | `113` |  | `public override long Position {`
| 124 | `114` |  | `get { return stream_.Position; }`
| 6 | `115` |  | `set { stream_.Position = value; }`
|  | `116` |  | `}`
|  | `117` |  | ``
|  | `118` |  | `public override bool CanWrite {`
| 0 | `119` |  | `get { return stream_.CanWrite; }`
|  | `120` |  | `}`
|  | `121` |  | ``
|  | `122` |  | `public override void Flush()`
|  | `123` |  | `{`
| 0 | `124` |  | `stream_.Flush();`
| 0 | `125` |  | `}`
|  | `126` |  | ``
|  | `127` |  | `public override long Seek(long offset, SeekOrigin origin)`
|  | `128` |  | `{`
| 131329 | `129` |  | `return stream_.Seek(offset, origin);`
|  | `130` |  | `}`
|  | `131` |  | ``
|  | `132` |  | `public override void SetLength(long value)`
|  | `133` |  | `{`
| 3 | `134` |  | `stream_.SetLength(value);`
| 3 | `135` |  | `}`
|  | `136` |  | ``
|  | `137` |  | `public override int Read(byte[] buffer, int offset, int count)`
|  | `138` |  | `{`
| 1 | `139` |  | `return stream_.Read(buffer, offset, count);`
|  | `140` |  | `}`
|  | `141` |  | ``
|  | `142` |  | `public override void Write(byte[] buffer, int offset, int count)`
|  | `143` |  | `{`
| 9 | `144` |  | `stream_.Write(buffer, offset, count);`
| 9 | `145` |  | `}`
|  | `146` |  | ``
|  | `147` |  | `/// <summary>`
|  | `148` |  | `/// Close the stream.`
|  | `149` |  | `/// </summary>`
|  | `150` |  | `/// <remarks>`
|  | `151` |  | `/// The underlying stream is closed only if <see cref="IsStreamOwner"/> is true.`
|  | `152` |  | `/// </remarks>`
|  | `153` |  | `override public void Close()`
|  | `154` |  | `{`
| 254 | `155` |  | `Stream toClose = stream_;`
| 254 | `156` |  | `stream_ = null;`
| 254 | `157` |  | `if (isOwner_ && (toClose != null)) {`
| 1 | `158` |  | `isOwner_ = false;`
| 1 | `159` |  | `toClose.Close();`
|  | `160` |  | `}`
| 254 | `161` |  | `}`
|  | `162` |  | `#endregion`
|  | `163` |  | ``
|  | `164` |  | `// Write the local file header`
|  | `165` |  | `// TODO: ZipHelperStream.WriteLocalHeader is not yet used and needs checking for ZipFile and ZipOuptutStream usage`
|  | `166` |  | `void WriteLocalHeader(ZipEntry entry, EntryPatchData patchData)`
|  | `167` |  | `{`
| 0 | `168` |  | `CompressionMethod method = entry.CompressionMethod;`
| 0 | `169` |  | `bool headerInfoAvailable = true; // How to get this?`
| 0 | `170` |  | `bool patchEntryHeader = false;`
|  | `171` |  | ``
| 0 | `172` |  | `WriteLEInt(ZipConstants.LocalHeaderSignature);`
|  | `173` |  | ``
| 0 | `174` |  | `WriteLEShort(entry.Version);`
| 0 | `175` |  | `WriteLEShort(entry.Flags);`
| 0 | `176` |  | `WriteLEShort((byte)method);`
| 0 | `177` |  | `WriteLEInt((int)entry.DosTime);`
|  | `178` |  | ``
| 0 | `179` |  | `if (headerInfoAvailable == true) {`
| 0 | `180` |  | `WriteLEInt((int)entry.Crc);`
| 0 | `181` |  | `if (entry.LocalHeaderRequiresZip64) {`
| 0 | `182` |  | `WriteLEInt(-1);`
| 0 | `183` |  | `WriteLEInt(-1);`
| 0 | `184` |  | `} else {`
| 0 | `185` |  | `WriteLEInt(entry.IsCrypted ? (int)entry.CompressedSize + ZipConstants.CryptoHeaderSize : (int)entry.Compressed`
| 0 | `186` |  | `WriteLEInt((int)entry.Size);`
|  | `187` |  | `}`
| 0 | `188` |  | `} else {`
| 0 | `189` |  | `if (patchData != null) {`
| 0 | `190` |  | `patchData.CrcPatchOffset = stream_.Position;`
|  | `191` |  | `}`
| 0 | `192` |  | `WriteLEInt(0); // Crc`
|  | `193` |  | ``
| 0 | `194` |  | `if (patchData != null) {`
| 0 | `195` |  | `patchData.SizePatchOffset = stream_.Position;`
|  | `196` |  | `}`
|  | `197` |  | ``
|  | `198` |  | `// For local header both sizes appear in Zip64 Extended Information`
| 0 | `199` |  | `if (entry.LocalHeaderRequiresZip64 && patchEntryHeader) {`
| 0 | `200` |  | `WriteLEInt(-1);`
| 0 | `201` |  | `WriteLEInt(-1);`
| 0 | `202` |  | `} else {`
| 0 | `203` |  | `WriteLEInt(0); // Compressed size`
| 0 | `204` |  | `WriteLEInt(0); // Uncompressed size`
|  | `205` |  | `}`
|  | `206` |  | `}`
|  | `207` |  | ``
| 0 | `208` |  | `byte[] name = ZipConstants.ConvertToArray(entry.Flags, entry.Name);`
|  | `209` |  | ``
| 0 | `210` |  | `if (name.Length > 0xFFFF) {`
| 0 | `211` |  | `throw new ZipException("Entry name too long.");`
|  | `212` |  | `}`
|  | `213` |  | ``
| 0 | `214` |  | `var ed = new ZipExtraData(entry.ExtraData);`
|  | `215` |  | ``
| 0 | `216` |  | `if (entry.LocalHeaderRequiresZip64 && (headerInfoAvailable || patchEntryHeader)) {`
| 0 | `217` |  | `ed.StartNewEntry();`
| 0 | `218` |  | `if (headerInfoAvailable) {`
| 0 | `219` |  | `ed.AddLeLong(entry.Size);`
| 0 | `220` |  | `ed.AddLeLong(entry.CompressedSize);`
| 0 | `221` |  | `} else {`
| 0 | `222` |  | `ed.AddLeLong(-1);`
| 0 | `223` |  | `ed.AddLeLong(-1);`
|  | `224` |  | `}`
| 0 | `225` |  | `ed.AddNewEntry(1);`
|  | `226` |  | ``
| 0 | `227` |  | `if (!ed.Find(1)) {`
| 0 | `228` |  | `throw new ZipException("Internal error cant find extra data");`
|  | `229` |  | `}`
|  | `230` |  | ``
| 0 | `231` |  | `if (patchData != null) {`
| 0 | `232` |  | `patchData.SizePatchOffset = ed.CurrentReadIndex;`
|  | `233` |  | `}`
| 0 | `234` |  | `} else {`
| 0 | `235` |  | `ed.Delete(1);`
|  | `236` |  | `}`
|  | `237` |  | ``
| 0 | `238` |  | `byte[] extra = ed.GetEntryData();`
|  | `239` |  | ``
| 0 | `240` |  | `WriteLEShort(name.Length);`
| 0 | `241` |  | `WriteLEShort(extra.Length);`
|  | `242` |  | ``
| 0 | `243` |  | `if (name.Length > 0) {`
| 0 | `244` |  | `stream_.Write(name, 0, name.Length);`
|  | `245` |  | `}`
|  | `246` |  | ``
| 0 | `247` |  | `if (entry.LocalHeaderRequiresZip64 && patchEntryHeader) {`
| 0 | `248` |  | `patchData.SizePatchOffset += stream_.Position;`
|  | `249` |  | `}`
|  | `250` |  | ``
| 0 | `251` |  | `if (extra.Length > 0) {`
| 0 | `252` |  | `stream_.Write(extra, 0, extra.Length);`
|  | `253` |  | `}`
| 0 | `254` |  | `}`
|  | `255` |  | ``
|  | `256` |  | `/// <summary>`
|  | `257` |  | `/// Locates a block with the desired <paramref name="signature"/>.`
|  | `258` |  | `/// </summary>`
|  | `259` |  | `/// <param name="signature">The signature to find.</param>`
|  | `260` |  | `/// <param name="endLocation">Location, marking the end of block.</param>`
|  | `261` |  | `/// <param name="minimumBlockSize">Minimum size of the block.</param>`
|  | `262` |  | `/// <param name="maximumVariableData">The maximum variable data.</param>`
|  | `263` |  | `/// <returns>Eeturns the offset of the first byte after the signature; -1 if not found</returns>`
|  | `264` |  | `public long LocateBlockWithSignature(int signature, long endLocation, int minimumBlockSize, int maximumVariableData)`
|  | `265` |  | `{`
| 118 | `266` |  | `long pos = endLocation - minimumBlockSize;`
| 118 | `267` |  | `if (pos < 0) {`
| 0 | `268` |  | `return -1;`
|  | `269` |  | `}`
|  | `270` |  | ``
| 118 | `271` |  | `long giveUpMarker = Math.Max(pos - maximumVariableData, 0);`
|  | `272` |  | ``
|  | `273` |  | `// TODO: This loop could be optimised for speed.`
|  | `274` |  | `do {`
| 131330 | `275` |  | `if (pos < giveUpMarker) {`
| 1 | `276` |  | `return -1;`
|  | `277` |  | `}`
| 131329 | `278` |  | `Seek(pos--, SeekOrigin.Begin);`
| 131329 | `279` |  | `} while (ReadLEInt() != signature);`
|  | `280` |  | ``
| 117 | `281` |  | `return Position;`
|  | `282` |  | `}`
|  | `283` |  | ``
|  | `284` |  | `/// <summary>`
|  | `285` |  | `/// Write Zip64 end of central directory records (File header and locator).`
|  | `286` |  | `/// </summary>`
|  | `287` |  | `/// <param name="noOfEntries">The number of entries in the central directory.</param>`
|  | `288` |  | `/// <param name="sizeEntries">The size of entries in the central directory.</param>`
|  | `289` |  | `/// <param name="centralDirOffset">The offset of the dentral directory.</param>`
|  | `290` |  | `public void WriteZip64EndOfCentralDirectory(long noOfEntries, long sizeEntries, long centralDirOffset)`
|  | `291` |  | `{`
| 1 | `292` |  | `long centralSignatureOffset = stream_.Position;`
| 1 | `293` |  | `WriteLEInt(ZipConstants.Zip64CentralFileHeaderSignature);`
| 1 | `294` |  | `WriteLELong(44); // Size of this record (total size of remaining fields in header or full size - 12)`
| 1 | `295` |  | `WriteLEShort(ZipConstants.VersionMadeBy); // Version made by`
| 1 | `296` |  | `WriteLEShort(ZipConstants.VersionZip64); // Version to extract`
| 1 | `297` |  | `WriteLEInt(0); // Number of this disk`
| 1 | `298` |  | `WriteLEInt(0); // number of the disk with the start of the central directory`
| 1 | `299` |  | `WriteLELong(noOfEntries); // No of entries on this disk`
| 1 | `300` |  | `WriteLELong(noOfEntries); // Total No of entries in central directory`
| 1 | `301` |  | `WriteLELong(sizeEntries); // Size of the central directory`
| 1 | `302` |  | `WriteLELong(centralDirOffset); // offset of start of central directory`
|  | `303` |  | `// zip64 extensible data sector not catered for here (variable size)`
|  | `304` |  | ``
|  | `305` |  | `// Write the Zip64 end of central directory locator`
| 1 | `306` |  | `WriteLEInt(ZipConstants.Zip64CentralDirLocatorSignature);`
|  | `307` |  | ``
|  | `308` |  | `// no of the disk with the start of the zip64 end of central directory`
| 1 | `309` |  | `WriteLEInt(0);`
|  | `310` |  | ``
|  | `311` |  | `// relative offset of the zip64 end of central directory record`
| 1 | `312` |  | `WriteLELong(centralSignatureOffset);`
|  | `313` |  | ``
|  | `314` |  | `// total number of disks`
| 1 | `315` |  | `WriteLEInt(1);`
| 1 | `316` |  | `}`
|  | `317` |  | ``
|  | `318` |  | `/// <summary>`
|  | `319` |  | `/// Write the required records to end the central directory.`
|  | `320` |  | `/// </summary>`
|  | `321` |  | `/// <param name="noOfEntries">The number of entries in the directory.</param>`
|  | `322` |  | `/// <param name="sizeEntries">The size of the entries in the directory.</param>`
|  | `323` |  | `/// <param name="startOfCentralDirectory">The start of the central directory.</param>`
|  | `324` |  | `/// <param name="comment">The archive comment. (This can be null).</param>`
|  | `325` |  | `public void WriteEndOfCentralDirectory(long noOfEntries, long sizeEntries,`
|  | `326` |  | `long startOfCentralDirectory, byte[] comment)`
|  | `327` |  | `{`
|  | `328` |  | ``
| 131 | `329` |  | `if ((noOfEntries >= 0xffff) ||`
| 131 | `330` |  | `(startOfCentralDirectory >= 0xffffffff) ||`
| 131 | `331` |  | `(sizeEntries >= 0xffffffff)) {`
| 1 | `332` |  | `WriteZip64EndOfCentralDirectory(noOfEntries, sizeEntries, startOfCentralDirectory);`
|  | `333` |  | `}`
|  | `334` |  | ``
| 131 | `335` |  | `WriteLEInt(ZipConstants.EndOfCentralDirectorySignature);`
|  | `336` |  | ``
|  | `337` |  | `// TODO: ZipFile Multi disk handling not done`
| 130 | `338` |  | `WriteLEShort(0); // number of this disk`
| 130 | `339` |  | `WriteLEShort(0); // no of disk with start of central dir`
|  | `340` |  | ``
|  | `341` |  | ``
|  | `342` |  | `// Number of entries`
| 130 | `343` |  | `if (noOfEntries >= 0xffff) {`
| 1 | `344` |  | `WriteLEUshort(0xffff); // Zip64 marker`
| 1 | `345` |  | `WriteLEUshort(0xffff);`
| 1 | `346` |  | `} else {`
| 129 | `347` |  | `WriteLEShort((short)noOfEntries); // entries in central dir for this disk`
| 129 | `348` |  | `WriteLEShort((short)noOfEntries); // total entries in central directory`
|  | `349` |  | `}`
|  | `350` |  | ``
|  | `351` |  | `// Size of the central directory`
| 130 | `352` |  | `if (sizeEntries >= 0xffffffff) {`
| 0 | `353` |  | `WriteLEUint(0xffffffff); // Zip64 marker`
| 0 | `354` |  | `} else {`
| 130 | `355` |  | `WriteLEInt((int)sizeEntries);`
|  | `356` |  | `}`
|  | `357` |  | ``
|  | `358` |  | ``
|  | `359` |  | `// offset of start of central directory`
| 130 | `360` |  | `if (startOfCentralDirectory >= 0xffffffff) {`
| 0 | `361` |  | `WriteLEUint(0xffffffff); // Zip64 marker`
| 0 | `362` |  | `} else {`
| 130 | `363` |  | `WriteLEInt((int)startOfCentralDirectory);`
|  | `364` |  | `}`
|  | `365` |  | ``
| 130 | `366` |  | `int commentLength = (comment != null) ? comment.Length : 0;`
|  | `367` |  | ``
| 130 | `368` |  | `if (commentLength > 0xffff) {`
| 0 | `369` |  | `throw new ZipException(string.Format("Comment length({0}) is too long can only be 64K", commentLength));`
|  | `370` |  | `}`
|  | `371` |  | ``
| 130 | `372` |  | `WriteLEShort(commentLength);`
|  | `373` |  | ``
| 130 | `374` |  | `if (commentLength > 0) {`
| 5 | `375` |  | `Write(comment, 0, comment.Length);`
|  | `376` |  | `}`
| 130 | `377` |  | `}`
|  | `378` |  | ``
|  | `379` |  | `#region LE value reading/writing`
|  | `380` |  | `/// <summary>`
|  | `381` |  | `/// Read an unsigned short in little endian byte order.`
|  | `382` |  | `/// </summary>`
|  | `383` |  | `/// <returns>Returns the value read.</returns>`
|  | `384` |  | `/// <exception cref="IOException">`
|  | `385` |  | `/// An i/o error occurs.`
|  | `386` |  | `/// </exception>`
|  | `387` |  | `/// <exception cref="EndOfStreamException">`
|  | `388` |  | `/// The file ends prematurely`
|  | `389` |  | `/// </exception>`
|  | `390` |  | `public int ReadLEShort()`
|  | `391` |  | `{`
| 262792 | `392` |  | `int byteValue1 = stream_.ReadByte();`
|  | `393` |  | ``
| 262792 | `394` |  | `if (byteValue1 < 0) {`
| 0 | `395` |  | `throw new EndOfStreamException();`
|  | `396` |  | `}`
|  | `397` |  | ``
| 262792 | `398` |  | `int byteValue2 = stream_.ReadByte();`
| 262792 | `399` |  | `if (byteValue2 < 0) {`
| 0 | `400` |  | `throw new EndOfStreamException();`
|  | `401` |  | `}`
|  | `402` |  | ``
| 262792 | `403` |  | `return byteValue1 | (byteValue2 << 8);`
|  | `404` |  | `}`
|  | `405` |  | ``
|  | `406` |  | `/// <summary>`
|  | `407` |  | `/// Read an int in little endian byte order.`
|  | `408` |  | `/// </summary>`
|  | `409` |  | `/// <returns>Returns the value read.</returns>`
|  | `410` |  | `/// <exception cref="IOException">`
|  | `411` |  | `/// An i/o error occurs.`
|  | `412` |  | `/// </exception>`
|  | `413` |  | `/// <exception cref="System.IO.EndOfStreamException">`
|  | `414` |  | `/// The file ends prematurely`
|  | `415` |  | `/// </exception>`
|  | `416` |  | `public int ReadLEInt()`
|  | `417` |  | `{`
| 131395 | `418` |  | `return ReadLEShort() | (ReadLEShort() << 16);`
|  | `419` |  | `}`
|  | `420` |  | ``
|  | `421` |  | `/// <summary>`
|  | `422` |  | `/// Read a long in little endian byte order.`
|  | `423` |  | `/// </summary>`
|  | `424` |  | `/// <returns>The value read.</returns>`
|  | `425` |  | `public long ReadLELong()`
|  | `426` |  | `{`
| 9 | `427` |  | `return (uint)ReadLEInt() | ((long)ReadLEInt() << 32);`
|  | `428` |  | `}`
|  | `429` |  | ``
|  | `430` |  | `/// <summary>`
|  | `431` |  | `/// Write an unsigned short in little endian byte order.`
|  | `432` |  | `/// </summary>`
|  | `433` |  | `/// <param name="value">The value to write.</param>`
|  | `434` |  | `public void WriteLEShort(int value)`
|  | `435` |  | `{`
| 1545 | `436` |  | `stream_.WriteByte((byte)(value & 0xff));`
| 1544 | `437` |  | `stream_.WriteByte((byte)((value >> 8) & 0xff));`
| 1544 | `438` |  | `}`
|  | `439` |  | ``
|  | `440` |  | `/// <summary>`
|  | `441` |  | `/// Write a ushort in little endian byte order.`
|  | `442` |  | `/// </summary>`
|  | `443` |  | `/// <param name="value">The value to write.</param>`
|  | `444` |  | `public void WriteLEUshort(ushort value)`
|  | `445` |  | `{`
| 2 | `446` |  | `stream_.WriteByte((byte)(value & 0xff));`
| 2 | `447` |  | `stream_.WriteByte((byte)(value >> 8));`
| 2 | `448` |  | `}`
|  | `449` |  | ``
|  | `450` |  | `/// <summary>`
|  | `451` |  | `/// Write an int in little endian byte order.`
|  | `452` |  | `/// </summary>`
|  | `453` |  | `/// <param name="value">The value to write.</param>`
|  | `454` |  | `public void WriteLEInt(int value)`
|  | `455` |  | `{`
| 444 | `456` |  | `WriteLEShort(value);`
| 444 | `457` |  | `WriteLEShort(value >> 16);`
| 443 | `458` |  | `}`
|  | `459` |  | ``
|  | `460` |  | `/// <summary>`
|  | `461` |  | `/// Write a uint in little endian byte order.`
|  | `462` |  | `/// </summary>`
|  | `463` |  | `/// <param name="value">The value to write.</param>`
|  | `464` |  | `public void WriteLEUint(uint value)`
|  | `465` |  | `{`
| 0 | `466` |  | `WriteLEUshort((ushort)(value & 0xffff));`
| 0 | `467` |  | `WriteLEUshort((ushort)(value >> 16));`
| 0 | `468` |  | `}`
|  | `469` |  | ``
|  | `470` |  | `/// <summary>`
|  | `471` |  | `/// Write a long in little endian byte order.`
|  | `472` |  | `/// </summary>`
|  | `473` |  | `/// <param name="value">The value to write.</param>`
|  | `474` |  | `public void WriteLELong(long value)`
|  | `475` |  | `{`
| 12 | `476` |  | `WriteLEInt((int)value);`
| 12 | `477` |  | `WriteLEInt((int)(value >> 32));`
| 12 | `478` |  | `}`
|  | `479` |  | ``
|  | `480` |  | `/// <summary>`
|  | `481` |  | `/// Write a ulong in little endian byte order.`
|  | `482` |  | `/// </summary>`
|  | `483` |  | `/// <param name="value">The value to write.</param>`
|  | `484` |  | `public void WriteLEUlong(ulong value)`
|  | `485` |  | `{`
| 0 | `486` |  | `WriteLEUint((uint)(value & 0xffffffff));`
| 0 | `487` |  | `WriteLEUint((uint)(value >> 32));`
| 0 | `488` |  | `}`
|  | `489` |  | ``
|  | `490` |  | `#endregion`
|  | `491` |  | ``
|  | `492` |  | `/// <summary>`
|  | `493` |  | `/// Write a data descriptor.`
|  | `494` |  | `/// </summary>`
|  | `495` |  | `/// <param name="entry">The entry to write a descriptor for.</param>`
|  | `496` |  | `/// <returns>Returns the number of descriptor bytes written.</returns>`
|  | `497` |  | `public int WriteDataDescriptor(ZipEntry entry)`
|  | `498` |  | `{`
| 5 | `499` |  | `if (entry == null) {`
| 0 | `500` |  | `throw new ArgumentNullException(nameof(entry));`
|  | `501` |  | `}`
|  | `502` |  | ``
| 5 | `503` |  | `int result = 0;`
|  | `504` |  | ``
|  | `505` |  | `// Add data descriptor if flagged as required`
| 5 | `506` |  | `if ((entry.Flags & (int)GeneralBitFlags.Descriptor) != 0) {`
|  | `507` |  | `// The signature is not PKZIP originally but is now described as optional`
|  | `508` |  | `// in the PKZIP Appnote documenting trhe format.`
| 5 | `509` |  | `WriteLEInt(ZipConstants.DataDescriptorSignature);`
| 5 | `510` |  | `WriteLEInt(unchecked((int)(entry.Crc)));`
|  | `511` |  | ``
| 5 | `512` |  | `result += 8;`
|  | `513` |  | ``
| 5 | `514` |  | `if (entry.LocalHeaderRequiresZip64) {`
| 0 | `515` |  | `WriteLELong(entry.CompressedSize);`
| 0 | `516` |  | `WriteLELong(entry.Size);`
| 0 | `517` |  | `result += 16;`
| 0 | `518` |  | `} else {`
| 5 | `519` |  | `WriteLEInt((int)entry.CompressedSize);`
| 5 | `520` |  | `WriteLEInt((int)entry.Size);`
| 5 | `521` |  | `result += 8;`
|  | `522` |  | `}`
|  | `523` |  | `}`
|  | `524` |  | ``
| 5 | `525` |  | `return result;`
|  | `526` |  | `}`
|  | `527` |  | ``
|  | `528` |  | `/// <summary>`
|  | `529` |  | `/// Read data descriptor at the end of compressed data.`
|  | `530` |  | `/// </summary>`
|  | `531` |  | `/// <param name="zip64">if set to <c>true</c> [zip64].</param>`
|  | `532` |  | `/// <param name="data">The data to fill in.</param>`
|  | `533` |  | `/// <returns>Returns the number of bytes read in the descriptor.</returns>`
|  | `534` |  | `public void ReadDataDescriptor(bool zip64, DescriptorData data)`
|  | `535` |  | `{`
| 13 | `536` |  | `int intValue = ReadLEInt();`
|  | `537` |  | ``
|  | `538` |  | `// In theory this may not be a descriptor according to PKZIP appnote.`
|  | `539` |  | `// In practise its always there.`
| 13 | `540` |  | `if (intValue != ZipConstants.DataDescriptorSignature) {`
| 0 | `541` |  | `throw new ZipException("Data descriptor signature not found");`
|  | `542` |  | `}`
|  | `543` |  | ``
| 13 | `544` |  | `data.Crc = ReadLEInt();`
|  | `545` |  | ``
| 13 | `546` |  | `if (zip64) {`
| 3 | `547` |  | `data.CompressedSize = ReadLELong();`
| 3 | `548` |  | `data.Size = ReadLELong();`
| 3 | `549` |  | `} else {`
| 10 | `550` |  | `data.CompressedSize = ReadLEInt();`
| 10 | `551` |  | `data.Size = ReadLEInt();`
|  | `552` |  | `}`
| 10 | `553` |  | `}`
|  | `554` |  | ``
|  | `555` |  | `#region Instance Fields`
|  | `556` |  | `bool isOwner_;`
|  | `557` |  | `Stream stream_;`
|  | `558` |  | `#endregion`
|  | `559` |  | `}`
|  | `560` |  | `}`