Exemple #1
0
        public static bool IsZipMulti(Stream stream, string password = null)
        {
            StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding());

            try
            {
                ZipHeader header = headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split);
                if (header is null)
                {
                    if (stream.CanSeek) //could be multipart. Test for central directory - might not be z64 safe
                    {
                        SeekableZipHeaderFactory z = new SeekableZipHeaderFactory(password, new ArchiveEncoding());
                        var x = z.ReadSeekableHeader(stream).FirstOrDefault();
                        return(x?.ZipHeaderType == ZipHeaderType.DirectoryEntry);
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(Enum.IsDefined(typeof(ZipHeaderType), header.ZipHeaderType));
            }
            catch (CryptographicException)
            {
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #2
0
        public static bool IsZipFile(Stream stream, string password = null)
        {
            StreamingZipHeaderFactory headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding());

            try
            {
                ZipHeader header = headerFactory.ReadStreamHeader(stream).FirstOrDefault(x => x.ZipHeaderType != ZipHeaderType.Split);
                if (header is null)
                {
                    return(false);
                }
                return(Enum.IsDefined(typeof(ZipHeaderType), header.ZipHeaderType));
            }
            catch (CryptographicException)
            {
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        public static bool IsZipFile(Stream stream, string password)
        {
            StreamingZipHeaderFactory factory = new StreamingZipHeaderFactory(password);

            try
            {
                ZipHeader header = Enumerable.FirstOrDefault <ZipHeader>(factory.ReadStreamHeader(stream), delegate(ZipHeader x) {
                    return(x.ZipHeaderType != ZipHeaderType.Split);
                });
                if (header == null)
                {
                    return(false);
                }
                return(Enum.IsDefined(typeof(ZipHeaderType), header.ZipHeaderType));
            }
            catch (CryptographicException)
            {
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #4
0
 internal ZipReader(Stream stream, ReaderOptions options)
     : base(options, ArchiveType.Zip)
 {
     Volume         = new ZipVolume(stream, options);
     _headerFactory = new StreamingZipHeaderFactory(options.Password, options.ArchiveEncoding);
 }
Exemple #5
0
 internal ZipReader(Stream stream, Options options, string password)
     : base(options, ArchiveType.Zip)
 {
     volume        = new ZipVolume(stream, options);
     headerFactory = new StreamingZipHeaderFactory(password);
 }