Beispiel #1
0
        /// <summary>
        /// Get a Stream for reading the specified entry
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public Stream GetInputStream(ZipEntry entry)
        {
            if (entry.Size == 0)
            {
                return(null);
            }

            if (entries == null)
            {
                throw new InvalidOperationException("ZipFile has closed");
            }

            int index = (int)entry.ZipFileIndex;

            if (index < 0 || index >= entries.Length || entries[index].Name != entry.Name)
            {
                throw new IndexOutOfRangeException();
            }

            // WARNING
            // should parse the Local Header to get the data address
            // Maximum Size of the Local Header is ... 16+64K*2
            //
            // So the HTTP request should ask for the big local header, but actually the
            // additional data is not downloaded.
            // Optionally use an additional Request to be really precise
            //HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseUrl);

            int limit = (int)(entry.Offset + entry.CompressedSize + 16 + 65536 * 2);

            if (limit >= MaxFileOffset)
            {
                limit = MaxFileOffset - 1;
            }
            //req.AddRange((int)entry.Offset, limit);
            //HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            //Stream baseStream = res.GetResponseStream();

            Stream baseStream = protocolProvider.CreateStream(this.url, (int)entry.Offset, limit);

            // skips all the header
            SkipLocalHeader(baseStream, entries[index]);
            CompressionMethod method = entries[index].CompressionMethod;

            Stream istr = new PartialInputStream(baseStream, entries[index].CompressedSize);

            switch (method)
            {
            case CompressionMethod.Stored:
                return(istr);

            case CompressionMethod.Deflated:
                return(new InflaterInputStream(istr, new Inflater(true)));

            case (CompressionMethod)12:
                return(new BZip2InputStream(istr));

            default:
                throw new ZipException("Unknown compression method " + method);
            }
        }
Beispiel #2
0
		/// <summary>
		/// Get a Stream for reading the specified entry
		/// </summary>
		/// <param name="entry"></param>
		/// <returns></returns>
		public Stream GetInputStream(ZipEntry entry)
		{
			if(entry.Size == 0)
				return null;

			if (entries == null) 
			{
				throw new InvalidOperationException("ZipFile has closed");
			}
			
			int index = (int)entry.ZipFileIndex;
			if (index < 0 || index >= entries.Length || entries[index].Name != entry.Name) 
			{
				throw new IndexOutOfRangeException();
			}
			
			// WARNING
			// should parse the Local Header to get the data address
			// Maximum Size of the Local Header is ... 16+64K*2
			//
			// So the HTTP request should ask for the big local header, but actually the
			// additional data is not downloaded.
			// Optionally use an additional Request to be really precise
			//HttpWebRequest req = (HttpWebRequest)WebRequest.Create(baseUrl);

			int limit = (int)(entry.Offset+entry.CompressedSize+16+65536*2);
			if(limit >= MaxFileOffset)
				limit = MaxFileOffset-1; 
			//req.AddRange((int)entry.Offset, limit);
			//HttpWebResponse res = (HttpWebResponse)req.GetResponse();
			//Stream baseStream = res.GetResponseStream();

            Stream baseStream = protocolProvider.CreateStream(this.url, (int)entry.Offset, limit);

			// skips all the header
			SkipLocalHeader(baseStream, entries[index]);
			CompressionMethod method = entries[index].CompressionMethod;

			Stream istr = new PartialInputStream(baseStream, entries[index].CompressedSize);
			switch (method) 
			{
				case CompressionMethod.Stored:
					return istr;
				case CompressionMethod.Deflated:
					return new InflaterInputStream(istr, new Inflater(true));
				case (CompressionMethod)12:
					return new BZip2InputStream(istr);
				default:
					throw new ZipException("Unknown compression method " + method);
			}
        }