Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <param name="mode"></param>
        public ZipFileStream(ZipFileImpl file, FileMode mode)
            : base()
        {
            this.zipFile = file;
            this.mode = mode;

            // Read in whole zip entry
            if (this.mode == FileMode.Open || this.mode == FileMode.Append) {
                // Can't open non existing zip
                if (!File.Exists(this.zipFile.ZipPath))
                    return;

                ZipFile zipFile = file.OpenZipFile();

                try {
                    if (file.ZipEntry == null) {
                        zipFile.Close();
                        return;
                    }

                    Stream stream = zipFile.GetInputStream(file.ZipEntry);
                    byte[] buff = new byte[1024];
                    int len;

                    // Read and stream chunks
                    try {
                        while ((len = stream.Read(buff, 0, 1024)) > 0)
                            this.Write(buff, 0, len);
                    } finally {
                        stream.Close();
                    }

                    if (this.mode == FileMode.Open)
                        this.Seek(0, SeekOrigin.Begin);
                } finally {
                    zipFile.Close();
                }
            }
        }