ICSharpCode.SharpZipLib.Zip.ZipHelperStream.ReadLEShort C# (CSharp) Méthode

ReadLEShort() public méthode

Read an unsigned short in little endian byte order.
/// An i/o error occurs. /// /// The file ends prematurely ///
public ReadLEShort ( ) : int
Résultat int
        public int ReadLEShort()
        {
            int byteValue1 = stream_.ReadByte();

            if (byteValue1 < 0) {
                throw new EndOfStreamException();
            }

            int byteValue2 = stream_.ReadByte();
            if (byteValue2 < 0) {
                throw new EndOfStreamException();
            }

            return byteValue1 | (byteValue2 << 8);
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Set the data from the raw values provided.
        /// </summary>
        /// <param name="data">The raw data to extract values from.</param>
        /// <param name="index">The index to start extracting values from.</param>
        /// <param name="count">The number of bytes available.</param>
        public void SetData(byte[] data, int index, int count)
        {
            using (MemoryStream ms = new MemoryStream(data, index, count, false))
                using (ZipHelperStream helperStream = new ZipHelperStream(ms)) {
                    helperStream.ReadLEInt();             // Reserved
                    while (helperStream.Position < helperStream.Length)
                    {
                        int ntfsTag    = helperStream.ReadLEShort();
                        int ntfsLength = helperStream.ReadLEShort();
                        if (ntfsTag == 1)
                        {
                            if (ntfsLength >= 24)
                            {
                                long lastModificationTicks = helperStream.ReadLELong();
                                _lastModificationTime = DateTime.FromFileTimeUtc(lastModificationTicks);

                                long lastAccessTicks = helperStream.ReadLELong();
                                _lastAccessTime = DateTime.FromFileTimeUtc(lastAccessTicks);

                                long createTimeTicks = helperStream.ReadLELong();
                                _createTime = DateTime.FromFileTimeUtc(createTimeTicks);
                            }
                            break;
                        }
                        else
                        {
                            // An unknown NTFS tag so simply skip it.
                            helperStream.Seek(ntfsLength, SeekOrigin.Current);
                        }
                    }
                }
        }
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.ZipHelperStream::ReadLEShort