Mercurial > vba-linux
diff src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipIn.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/GZip/GZipIn.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,119 @@ 1.4 +// Archive/GZipIn.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#include "GZipIn.h" 1.9 + 1.10 +#include "Common/Defs.h" 1.11 +#include "Common/MyCom.h" 1.12 +#include "Windows/Defs.h" 1.13 + 1.14 +#include "../../Common/StreamUtils.h" 1.15 + 1.16 +extern "C" 1.17 +{ 1.18 + #include "../../../../C/7zCrc.h" 1.19 +} 1.20 + 1.21 +namespace NArchive { 1.22 +namespace NGZip { 1.23 + 1.24 +HRESULT CInArchive::ReadBytes(ISequentialInStream *inStream, void *data, UInt32 size) 1.25 +{ 1.26 + RINOK(ReadStream_FALSE(inStream, data, size)); 1.27 + m_Position += size; 1.28 + return S_OK; 1.29 +} 1.30 + 1.31 +HRESULT CInArchive::ReadByte(ISequentialInStream *inStream, Byte &value, UInt32 &crc) 1.32 +{ 1.33 + RINOK(ReadBytes(inStream, &value, 1)); 1.34 + crc = CRC_UPDATE_BYTE(crc, value); 1.35 + return S_OK; 1.36 +} 1.37 + 1.38 +HRESULT CInArchive::ReadUInt16(ISequentialInStream *inStream, UInt16 &value, UInt32 &crc) 1.39 +{ 1.40 + value = 0; 1.41 + for (int i = 0; i < 2; i++) 1.42 + { 1.43 + Byte b; 1.44 + RINOK(ReadByte(inStream, b, crc)); 1.45 + value |= (UInt16(b) << (8 * i)); 1.46 + } 1.47 + return S_OK; 1.48 +} 1.49 + 1.50 +HRESULT CInArchive::ReadUInt32(ISequentialInStream *inStream, UInt32 &value, UInt32 &crc) 1.51 +{ 1.52 + value = 0; 1.53 + for (int i = 0; i < 4; i++) 1.54 + { 1.55 + Byte b; 1.56 + RINOK(ReadByte(inStream, b, crc)); 1.57 + value |= (UInt32(b) << (8 * i)); 1.58 + } 1.59 + return S_OK; 1.60 +} 1.61 + 1.62 +HRESULT CInArchive::ReadZeroTerminatedString(ISequentialInStream *inStream, AString &resString, UInt32 &crc) 1.63 +{ 1.64 + resString.Empty(); 1.65 + for (;;) 1.66 + { 1.67 + Byte c; 1.68 + RINOK(ReadByte(inStream, c, crc)); 1.69 + if (c == 0) 1.70 + return S_OK; 1.71 + resString += char(c); 1.72 + } 1.73 +} 1.74 + 1.75 +HRESULT CInArchive::ReadHeader(ISequentialInStream *inStream, CItem &item) 1.76 +{ 1.77 + item.Clear(); 1.78 + m_Position = 0; 1.79 + 1.80 + UInt16 signature; 1.81 + UInt32 crc = CRC_INIT_VAL;; 1.82 + RINOK(ReadUInt16(inStream, signature, crc)); 1.83 + if (signature != kSignature) 1.84 + return S_FALSE; 1.85 + 1.86 + RINOK(ReadByte(inStream, item.CompressionMethod, crc)); 1.87 + RINOK(ReadByte(inStream, item.Flags, crc)); 1.88 + RINOK(ReadUInt32(inStream, item.Time, crc)); 1.89 + RINOK(ReadByte(inStream, item.ExtraFlags, crc)); 1.90 + RINOK(ReadByte(inStream, item.HostOS, crc)); 1.91 + 1.92 + if (item.ExtraFieldIsPresent()) 1.93 + { 1.94 + UInt16 extraSize; 1.95 + RINOK(ReadUInt16(inStream, extraSize, crc)); 1.96 + item.Extra.SetCapacity(extraSize); 1.97 + RINOK(ReadBytes(inStream, item.Extra, extraSize)); 1.98 + crc = CrcUpdate(crc, item.Extra, extraSize); 1.99 + } 1.100 + if (item.NameIsPresent()) 1.101 + RINOK(ReadZeroTerminatedString(inStream, item.Name, crc)); 1.102 + if (item.CommentIsPresent()) 1.103 + RINOK(ReadZeroTerminatedString(inStream, item.Comment, crc)); 1.104 + if (item.HeaderCRCIsPresent()) 1.105 + { 1.106 + UInt16 headerCRC; 1.107 + UInt32 dummy = 0; 1.108 + RINOK(ReadUInt16(inStream, headerCRC, dummy)); 1.109 + if ((UInt16)CRC_GET_DIGEST(crc) != headerCRC) 1.110 + return S_FALSE; 1.111 + } 1.112 + return S_OK; 1.113 +} 1.114 + 1.115 +HRESULT CInArchive::ReadPostHeader(ISequentialInStream *inStream, CItem &item) 1.116 +{ 1.117 + UInt32 dummy = 0; 1.118 + RINOK(ReadUInt32(inStream, item.FileCRC, dummy)); 1.119 + return ReadUInt32(inStream, item.UnPackSize32, dummy); 1.120 +} 1.121 + 1.122 +}}