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
        internal override IEnumerable <ZipEntry> GetEntries(Stream stream)
        {
            foreach (ZipHeader h in headerFactory.ReadStreamHeader(stream))
            {
                if (h != null)
                {
                    switch (h.ZipHeaderType)
                    {
                    case ZipHeaderType.LocalEntry: {
                        yield return(new ZipEntry(new StreamingZipFilePart(h as LocalEntryHeader,
                                                                           stream)));
                    }
                    break;

                    case ZipHeaderType.DirectoryEnd: {
                        yield break;
                    }
                    }
                }
            }
        }
Exemple #3
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);
            }
        }