Пример #1
0
        private async Task <PartialZipInfo> Open()
        {
            bool supportsPartialZip = await _httpService.SupportsPartialZip();

            if (!supportsPartialZip)
            {
                throw new PartialZipNotSupportedException("The web server does not support PartialZip as byte ranges are not accepted.");
            }

            PartialZipInfo info = new PartialZipInfo();

            info.Length = await _httpService.GetContentLength();

            byte[] eocdBuffer = await _httpService.GetRange(info.Length - EndOfCentralDirectory.Size, info.Length - 1);

            info.EndOfCentralDirectory = new EndOfCentralDirectory(eocdBuffer);

            ulong startCD, endCD;

            if (info.EndOfCentralDirectory.IsZip64)
            {
                byte[] eocdLocator64Buffer = await _httpService.GetRange(info.Length - EndOfCentralDirectory.Size - EndOfCentralDirectoryLocator64.Size, info.Length - EndOfCentralDirectory.Size);

                info.EndOfCentralDirectoryLocator64 = new EndOfCentralDirectoryLocator64(eocdLocator64Buffer);

                byte[] eocd64Buffer = await _httpService.GetRange(info.EndOfCentralDirectoryLocator64.EndOfCentralDirectory64StartOffset, info.EndOfCentralDirectoryLocator64.EndOfCentralDirectory64StartOffset + EndOfCentralDirectory64.Size - 1);

                info.EndOfCentralDirectory64 = new EndOfCentralDirectory64(eocd64Buffer);

                startCD = info.EndOfCentralDirectory64.CentralDirectoryStartOffset;
                endCD   = info.EndOfCentralDirectory64.CentralDirectoryStartOffset + info.EndOfCentralDirectory64.CentralDirectorySize + EndOfCentralDirectory64.Size - 1;
                info.CentralDirectoryEntries = info.EndOfCentralDirectory64.CentralDirectoryRecordCount;
            }
            else
            {
                startCD = info.EndOfCentralDirectory.CentralDirectoryStartOffset;
                endCD   = info.EndOfCentralDirectory.CentralDirectoryStartOffset + info.EndOfCentralDirectory.CentralDirectorySize + EndOfCentralDirectory.Size - 1;
                info.CentralDirectoryEntries = info.EndOfCentralDirectory.CentralDirectoryRecordCount;
            }

            byte[] cdBuffer = await _httpService.GetRange(startCD, endCD);

            info.CentralDirectory = CentralDirectoryHeader.GetFromBuffer(cdBuffer, info.CentralDirectoryEntries);

            return(info);
        }