/// <summary> /// Deserializes raw data from zip directory entry into this object /// </summary> /// <param name="data"> /// The data. /// </param> /// <param name="offset"> /// The offset. /// </param> /// <param name="count"> /// The count. /// </param> public void SetData(byte[] data, int offset, int count) { using (var ms = new MemoryStream(data, offset, count, false)) using (var helperStream = new TaggedDataHelperStream(ms)) { this.version = helperStream.ReadByte(); this.uidSize = helperStream.ReadByte(); this.Uid = this.uidSize == 4 ? helperStream.ReadLEInt() : helperStream.ReadLEShort(); this.gidSize = helperStream.ReadByte(); this.Gid = this.gidSize == 4 ? helperStream.ReadLEInt() : helperStream.ReadLEShort(); } }
/// <summary> /// Serializes this instance to byte array to write into zip directory. /// </summary> /// <returns> /// Raw byte array to write into zip directory entry /// </returns> /// <exception cref="ZipException"> /// Unsupported integer size for Unix UID or GID /// </exception> public byte[] GetData() { using (var ms = new MemoryStream()) using (var helperStream = new TaggedDataHelperStream(ms)) { helperStream.IsStreamOwner = false; helperStream.WriteByte((byte)this.version); helperStream.WriteByte((byte)this.uidSize); switch (this.uidSize) { case 2: helperStream.WriteLEShort(this.Uid); break; case 4: helperStream.WriteLEInt(this.Uid); break; default: throw new ZipException($"Unsupported integer size {this.uidSize} for Unix UID"); } helperStream.WriteByte((byte)this.gidSize); switch (this.gidSize) { case 2: helperStream.WriteLEShort(this.Gid); break; case 4: helperStream.WriteLEInt(this.Gid); break; default: throw new ZipException($"Unsupported integer size {this.uidSize} for Unix GID"); } return(ms.ToArray()); } }