ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream.Finish C# (CSharp) Méthode

Finish() public méthode

Finishes the stream by calling finish() on the deflater.
/// Not all input is deflated ///
public Finish ( ) : void
Résultat void
        public virtual void Finish()
        {
            deflater_.Finish();
            while (!deflater_.IsFinished) {
                int len = deflater_.Deflate(buffer_, 0, buffer_.Length);
                if (len <= 0) {
                    break;
                }

                if (cryptoTransform_ != null) {
                    EncryptBlock(buffer_, 0, len);
                }

                baseOutputStream_.Write(buffer_, 0, len);
            }

            if (!deflater_.IsFinished) {
                throw new SharpZipBaseException("Can't deflate all input?");
            }

            baseOutputStream_.Flush();

            if (cryptoTransform_ != null) {
                if (cryptoTransform_ is ZipAESTransform) {
                    AESAuthCode = ((ZipAESTransform)cryptoTransform_).GetAuthCode();
                }
                cryptoTransform_.Dispose();
                cryptoTransform_ = null;
            }
        }

Usage Example

		// netz.compress.ICompress implementation

		public long Compress(string file, string zipFile)
		{
			long length = -1;
			FileStream ifs = null;
			FileStream ofs = null;
			try
			{
				ifs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
				ofs = File.Open(zipFile, FileMode.Create, FileAccess.Write, FileShare.None);
				DeflaterOutputStream dos = new DeflaterOutputStream(ofs, new Deflater(Deflater.BEST_COMPRESSION));
				byte[] buff = new byte[ifs.Length];
				while(true)
				{
					int r = ifs.Read(buff, 0, buff.Length);
					if(r <= 0) break;
					dos.Write(buff, 0, r);
				}
				dos.Flush();
				dos.Finish();
				length = dos.Length;
				dos.Close();
			}
			finally
			{
				if(ifs != null) ifs.Close();
				if(ofs != null) ofs.Close();
			}
			return length;
		}
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream::Finish