Import TechBot
[reactos.git] / irc / TechBot / Compression / Inflater.cs
1 // Inflater.cs
2 // Copyright (C) 2001 Mike Krueger
3 //
4 // This file was translated from java, it was part of the GNU Classpath
5 // Copyright (C) 2001 Free Software Foundation, Inc.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 //
21 // Linking this library statically or dynamically with other modules is
22 // making a combined work based on this library. Thus, the terms and
23 // conditions of the GNU General Public License cover the whole
24 // combination.
25 //
26 // As a special exception, the copyright holders of this library give you
27 // permission to link this library with independent modules to produce an
28 // executable, regardless of the license terms of these independent
29 // modules, and to copy and distribute the resulting executable under
30 // terms of your choice, provided that you also meet, for each linked
31 // independent module, the terms and conditions of the license of that
32 // module. An independent module is a module which is not derived from
33 // or based on this library. If you modify this library, you may extend
34 // this exception to your version of the library, but you are not
35 // obligated to do so. If you do not wish to do so, delete this
36 // exception statement from your version.
37
38 using System;
39
40 using ICSharpCode.SharpZipLib.Checksums;
41 using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
42
43 namespace ICSharpCode.SharpZipLib.Zip.Compression
44 {
45
46 /// <summary>
47 /// Inflater is used to decompress data that has been compressed according
48 /// to the "deflate" standard described in rfc1950.
49 ///
50 /// The usage is as following. First you have to set some input with
51 /// <code>setInput()</code>, then inflate() it. If inflate doesn't
52 /// inflate any bytes there may be three reasons:
53 /// <ul>
54 /// <li>needsInput() returns true because the input buffer is empty.
55 /// You have to provide more input with <code>setInput()</code>.
56 /// NOTE: needsInput() also returns true when, the stream is finished.
57 /// </li>
58 /// <li>needsDictionary() returns true, you have to provide a preset
59 /// dictionary with <code>setDictionary()</code>.</li>
60 /// <li>finished() returns true, the inflater has finished.</li>
61 /// </ul>
62 /// Once the first output byte is produced, a dictionary will not be
63 /// needed at a later stage.
64 ///
65 /// author of the original java version : John Leuner, Jochen Hoenicke
66 /// </summary>
67 public class Inflater
68 {
69 /// <summary>
70 /// Copy lengths for literal codes 257..285
71 /// </summary>
72 private static int[] CPLENS = {
73 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
74 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258
75 };
76
77 /// <summary>
78 /// Extra bits for literal codes 257..285
79 /// </summary>
80 private static int[] CPLEXT = {
81 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
82 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0
83 };
84
85 /// <summary>
86 /// Copy offsets for distance codes 0..29
87 /// </summary>
88 private static int[] CPDIST = {
89 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
90 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
91 8193, 12289, 16385, 24577
92 };
93
94 /// <summary>
95 /// Extra bits for distance codes
96 /// </summary>
97 private static int[] CPDEXT = {
98 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
99 7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
100 12, 12, 13, 13
101 };
102
103 /// <summary>
104 /// This are the state in which the inflater can be.
105 /// </summary>
106 private const int DECODE_HEADER = 0;
107 private const int DECODE_DICT = 1;
108 private const int DECODE_BLOCKS = 2;
109 private const int DECODE_STORED_LEN1 = 3;
110 private const int DECODE_STORED_LEN2 = 4;
111 private const int DECODE_STORED = 5;
112 private const int DECODE_DYN_HEADER = 6;
113 private const int DECODE_HUFFMAN = 7;
114 private const int DECODE_HUFFMAN_LENBITS = 8;
115 private const int DECODE_HUFFMAN_DIST = 9;
116 private const int DECODE_HUFFMAN_DISTBITS = 10;
117 private const int DECODE_CHKSUM = 11;
118 private const int FINISHED = 12;
119
120 /// <summary>
121 /// This variable contains the current state.
122 /// </summary>
123 private int mode;
124
125 /// <summary>
126 /// The adler checksum of the dictionary or of the decompressed
127 /// stream, as it is written in the header resp. footer of the
128 /// compressed stream.
129 /// Only valid if mode is DECODE_DICT or DECODE_CHKSUM.
130 /// </summary>
131 private int readAdler;
132
133 /// <summary>
134 /// The number of bits needed to complete the current state. This
135 /// is valid, if mode is DECODE_DICT, DECODE_CHKSUM,
136 /// DECODE_HUFFMAN_LENBITS or DECODE_HUFFMAN_DISTBITS.
137 /// </summary>
138 private int neededBits;
139 private int repLength, repDist;
140 private int uncomprLen;
141
142 /// <summary>
143 /// True, if the last block flag was set in the last block of the
144 /// inflated stream. This means that the stream ends after the
145 /// current block.
146 /// </summary>
147 private bool isLastBlock;
148
149 /// <summary>
150 /// The total number of inflated bytes.
151 /// </summary>
152 private int totalOut;
153
154 /// <summary>
155 /// The total number of bytes set with setInput(). This is not the
156 /// value returned by getTotalIn(), since this also includes the
157 /// unprocessed input.
158 /// </summary>
159 private int totalIn;
160
161 /// <summary>
162 /// This variable stores the nowrap flag that was given to the constructor.
163 /// True means, that the inflated stream doesn't contain a header nor the
164 /// checksum in the footer.
165 /// </summary>
166 private bool nowrap;
167
168 private StreamManipulator input;
169 private OutputWindow outputWindow;
170 private InflaterDynHeader dynHeader;
171 private InflaterHuffmanTree litlenTree, distTree;
172 private Adler32 adler;
173
174 /// <summary>
175 /// Creates a new inflater.
176 /// </summary>
177 public Inflater() : this(false)
178 {
179 }
180
181 /// <summary>
182 /// Creates a new inflater.
183 /// </summary>
184 /// <param name="nowrap">
185 /// true if no header and checksum field appears in the
186 /// stream. This is used for GZIPed input. For compatibility with
187 /// Sun JDK you should provide one byte of input more than needed in
188 /// this case.
189 /// </param>
190 public Inflater(bool nowrap)
191 {
192 this.nowrap = nowrap;
193 this.adler = new Adler32();
194 input = new StreamManipulator();
195 outputWindow = new OutputWindow();
196 mode = nowrap ? DECODE_BLOCKS : DECODE_HEADER;
197 }
198
199 /// <summary>
200 /// Resets the inflater so that a new stream can be decompressed. All
201 /// pending input and output will be discarded.
202 /// </summary>
203 public void Reset()
204 {
205 mode = nowrap ? DECODE_BLOCKS : DECODE_HEADER;
206 totalIn = totalOut = 0;
207 input.Reset();
208 outputWindow.Reset();
209 dynHeader = null;
210 litlenTree = null;
211 distTree = null;
212 isLastBlock = false;
213 adler.Reset();
214 }
215
216 /// <summary>
217 /// Decodes the deflate header.
218 /// </summary>
219 /// <returns>
220 /// false if more input is needed.
221 /// </returns>
222 /// <exception cref="System.FormatException">
223 /// if header is invalid.
224 /// </exception>
225 private bool DecodeHeader()
226 {
227 int header = input.PeekBits(16);
228 if (header < 0) {
229 return false;
230 }
231 input.DropBits(16);
232 /* The header is written in "wrong" byte order */
233 header = ((header << 8) | (header >> 8)) & 0xffff;
234 if (header % 31 != 0) {
235 throw new FormatException("Header checksum illegal");
236 }
237
238 if ((header & 0x0f00) != (Deflater.DEFLATED << 8)) {
239 throw new FormatException("Compression Method unknown");
240 }
241
242 /* Maximum size of the backwards window in bits.
243 * We currently ignore this, but we could use it to make the
244 * inflater window more space efficient. On the other hand the
245 * full window (15 bits) is needed most times, anyway.
246 int max_wbits = ((header & 0x7000) >> 12) + 8;
247 */
248
249 if ((header & 0x0020) == 0) { // Dictionary flag?
250 mode = DECODE_BLOCKS;
251 } else {
252 mode = DECODE_DICT;
253 neededBits = 32;
254 }
255 return true;
256 }
257
258 /// <summary>
259 /// Decodes the dictionary checksum after the deflate header.
260 /// </summary>
261 /// <returns>
262 /// false if more input is needed.
263 /// </returns>
264 private bool DecodeDict()
265 {
266 while (neededBits > 0) {
267 int dictByte = input.PeekBits(8);
268 if (dictByte < 0) {
269 return false;
270 }
271 input.DropBits(8);
272 readAdler = (readAdler << 8) | dictByte;
273 neededBits -= 8;
274 }
275 return false;
276 }
277
278 /// <summary>
279 /// Decodes the huffman encoded symbols in the input stream.
280 /// </summary>
281 /// <returns>
282 /// false if more input is needed, true if output window is
283 /// full or the current block ends.
284 /// </returns>
285 /// <exception cref="System.FormatException">
286 /// if deflated stream is invalid.
287 /// </exception>
288 private bool DecodeHuffman()
289 {
290 int free = outputWindow.GetFreeSpace();
291 while (free >= 258) {
292 int symbol;
293 switch (mode) {
294 case DECODE_HUFFMAN:
295 /* This is the inner loop so it is optimized a bit */
296 while (((symbol = litlenTree.GetSymbol(input)) & ~0xff) == 0) {
297 outputWindow.Write(symbol);
298 if (--free < 258) {
299 return true;
300 }
301 }
302 if (symbol < 257) {
303 if (symbol < 0) {
304 return false;
305 } else {
306 /* symbol == 256: end of block */
307 distTree = null;
308 litlenTree = null;
309 mode = DECODE_BLOCKS;
310 return true;
311 }
312 }
313
314 try {
315 repLength = CPLENS[symbol - 257];
316 neededBits = CPLEXT[symbol - 257];
317 } catch (Exception) {
318 throw new FormatException("Illegal rep length code");
319 }
320 goto case DECODE_HUFFMAN_LENBITS;/* fall through */
321 case DECODE_HUFFMAN_LENBITS:
322 if (neededBits > 0) {
323 mode = DECODE_HUFFMAN_LENBITS;
324 int i = input.PeekBits(neededBits);
325 if (i < 0) {
326 return false;
327 }
328 input.DropBits(neededBits);
329 repLength += i;
330 }
331 mode = DECODE_HUFFMAN_DIST;
332 goto case DECODE_HUFFMAN_DIST;/* fall through */
333 case DECODE_HUFFMAN_DIST:
334 symbol = distTree.GetSymbol(input);
335 if (symbol < 0) {
336 return false;
337 }
338 try {
339 repDist = CPDIST[symbol];
340 neededBits = CPDEXT[symbol];
341 } catch (Exception) {
342 throw new FormatException("Illegal rep dist code");
343 }
344
345 goto case DECODE_HUFFMAN_DISTBITS;/* fall through */
346 case DECODE_HUFFMAN_DISTBITS:
347 if (neededBits > 0) {
348 mode = DECODE_HUFFMAN_DISTBITS;
349 int i = input.PeekBits(neededBits);
350 if (i < 0) {
351 return false;
352 }
353 input.DropBits(neededBits);
354 repDist += i;
355 }
356 outputWindow.Repeat(repLength, repDist);
357 free -= repLength;
358 mode = DECODE_HUFFMAN;
359 break;
360 default:
361 throw new FormatException();
362 }
363 }
364 return true;
365 }
366
367 /// <summary>
368 /// Decodes the adler checksum after the deflate stream.
369 /// </summary>
370 /// <returns>
371 /// false if more input is needed.
372 /// </returns>
373 /// <exception cref="System.FormatException">
374 /// DataFormatException, if checksum doesn't match.
375 /// </exception>
376 private bool DecodeChksum()
377 {
378 while (neededBits > 0) {
379 int chkByte = input.PeekBits(8);
380 if (chkByte < 0) {
381 return false;
382 }
383 input.DropBits(8);
384 readAdler = (readAdler << 8) | chkByte;
385 neededBits -= 8;
386 }
387 if ((int) adler.Value != readAdler) {
388 throw new FormatException("Adler chksum doesn't match: " + (int)adler.Value + " vs. " + readAdler);
389 }
390 mode = FINISHED;
391 return false;
392 }
393
394 /// <summary>
395 /// Decodes the deflated stream.
396 /// </summary>
397 /// <returns>
398 /// false if more input is needed, or if finished.
399 /// </returns>
400 /// <exception cref="System.FormatException">
401 /// DataFormatException, if deflated stream is invalid.
402 /// </exception>
403 private bool Decode()
404 {
405 switch (mode) {
406 case DECODE_HEADER:
407 return DecodeHeader();
408 case DECODE_DICT:
409 return DecodeDict();
410 case DECODE_CHKSUM:
411 return DecodeChksum();
412
413 case DECODE_BLOCKS:
414 if (isLastBlock) {
415 if (nowrap) {
416 mode = FINISHED;
417 return false;
418 } else {
419 input.SkipToByteBoundary();
420 neededBits = 32;
421 mode = DECODE_CHKSUM;
422 return true;
423 }
424 }
425
426 int type = input.PeekBits(3);
427 if (type < 0) {
428 return false;
429 }
430 input.DropBits(3);
431
432 if ((type & 1) != 0) {
433 isLastBlock = true;
434 }
435 switch (type >> 1){
436 case DeflaterConstants.STORED_BLOCK:
437 input.SkipToByteBoundary();
438 mode = DECODE_STORED_LEN1;
439 break;
440 case DeflaterConstants.STATIC_TREES:
441 litlenTree = InflaterHuffmanTree.defLitLenTree;
442 distTree = InflaterHuffmanTree.defDistTree;
443 mode = DECODE_HUFFMAN;
444 break;
445 case DeflaterConstants.DYN_TREES:
446 dynHeader = new InflaterDynHeader();
447 mode = DECODE_DYN_HEADER;
448 break;
449 default:
450 throw new FormatException("Unknown block type "+type);
451 }
452 return true;
453
454 case DECODE_STORED_LEN1:
455 {
456 if ((uncomprLen = input.PeekBits(16)) < 0) {
457 return false;
458 }
459 input.DropBits(16);
460 mode = DECODE_STORED_LEN2;
461 }
462 goto case DECODE_STORED_LEN2; /* fall through */
463 case DECODE_STORED_LEN2:
464 {
465 int nlen = input.PeekBits(16);
466 if (nlen < 0) {
467 return false;
468 }
469 input.DropBits(16);
470 if (nlen != (uncomprLen ^ 0xffff)) {
471 throw new FormatException("broken uncompressed block");
472 }
473 mode = DECODE_STORED;
474 }
475 goto case DECODE_STORED;/* fall through */
476 case DECODE_STORED:
477 {
478 int more = outputWindow.CopyStored(input, uncomprLen);
479 uncomprLen -= more;
480 if (uncomprLen == 0) {
481 mode = DECODE_BLOCKS;
482 return true;
483 }
484 return !input.IsNeedingInput;
485 }
486
487 case DECODE_DYN_HEADER:
488 if (!dynHeader.Decode(input)) {
489 return false;
490 }
491
492 litlenTree = dynHeader.BuildLitLenTree();
493 distTree = dynHeader.BuildDistTree();
494 mode = DECODE_HUFFMAN;
495 goto case DECODE_HUFFMAN; /* fall through */
496 case DECODE_HUFFMAN:
497 case DECODE_HUFFMAN_LENBITS:
498 case DECODE_HUFFMAN_DIST:
499 case DECODE_HUFFMAN_DISTBITS:
500 return DecodeHuffman();
501 case FINISHED:
502 return false;
503 default:
504 throw new FormatException();
505 }
506 }
507
508 /// <summary>
509 /// Sets the preset dictionary. This should only be called, if
510 /// needsDictionary() returns true and it should set the same
511 /// dictionary, that was used for deflating. The getAdler()
512 /// function returns the checksum of the dictionary needed.
513 /// </summary>
514 /// <param name="buffer">
515 /// the dictionary.
516 /// </param>
517 /// <exception cref="System.InvalidOperationException">
518 /// if no dictionary is needed.
519 /// </exception>
520 /// <exception cref="System.ArgumentException">
521 /// if the dictionary checksum is wrong.
522 /// </exception>
523 public void SetDictionary(byte[] buffer)
524 {
525 SetDictionary(buffer, 0, buffer.Length);
526 }
527
528 /// <summary>
529 /// Sets the preset dictionary. This should only be called, if
530 /// needsDictionary() returns true and it should set the same
531 /// dictionary, that was used for deflating. The getAdler()
532 /// function returns the checksum of the dictionary needed.
533 /// </summary>
534 /// <param name="buffer">
535 /// the dictionary.
536 /// </param>
537 /// <param name="off">
538 /// the offset into buffer where the dictionary starts.
539 /// </param>
540 /// <param name="len">
541 /// the length of the dictionary.
542 /// </param>
543 /// <exception cref="System.InvalidOperationException">
544 /// if no dictionary is needed.
545 /// </exception>
546 /// <exception cref="System.ArgumentException">
547 /// if the dictionary checksum is wrong.
548 /// </exception>
549 /// <exception cref="System.ArgumentOutOfRangeException">
550 /// if the off and/or len are wrong.
551 /// </exception>
552 public void SetDictionary(byte[] buffer, int off, int len)
553 {
554 if (!IsNeedingDictionary) {
555 throw new InvalidOperationException();
556 }
557
558 adler.Update(buffer, off, len);
559 if ((int)adler.Value != readAdler) {
560 throw new ArgumentException("Wrong adler checksum");
561 }
562 adler.Reset();
563 outputWindow.CopyDict(buffer, off, len);
564 mode = DECODE_BLOCKS;
565 }
566
567 /// <summary>
568 /// Sets the input. This should only be called, if needsInput()
569 /// returns true.
570 /// </summary>
571 /// <param name="buf">
572 /// the input.
573 /// </param>
574 /// <exception cref="System.InvalidOperationException">
575 /// if no input is needed.
576 /// </exception>
577 public void SetInput(byte[] buf)
578 {
579 SetInput(buf, 0, buf.Length);
580 }
581
582 /// <summary>
583 /// Sets the input. This should only be called, if needsInput()
584 /// returns true.
585 /// </summary>
586 /// <param name="buf">
587 /// the input.
588 /// </param>
589 /// <param name="off">
590 /// the offset into buffer where the input starts.
591 /// </param>
592 /// <param name="len">
593 /// the length of the input.
594 /// </param>
595 /// <exception cref="System.InvalidOperationException">
596 /// if no input is needed.
597 /// </exception>
598 /// <exception cref="System.ArgumentOutOfRangeException">
599 /// if the off and/or len are wrong.
600 /// </exception>
601 public void SetInput(byte[] buf, int off, int len)
602 {
603 input.SetInput(buf, off, len);
604 totalIn += len;
605 }
606
607 /// <summary>
608 /// Inflates the compressed stream to the output buffer. If this
609 /// returns 0, you should check, whether needsDictionary(),
610 /// needsInput() or finished() returns true, to determine why no
611 /// further output is produced.
612 /// </summary>
613 /// <param name = "buf">
614 /// the output buffer.
615 /// </param>
616 /// <returns>
617 /// the number of bytes written to the buffer, 0 if no further
618 /// output can be produced.
619 /// </returns>
620 /// <exception cref="System.ArgumentOutOfRangeException">
621 /// if buf has length 0.
622 /// </exception>
623 /// <exception cref="System.FormatException">
624 /// if deflated stream is invalid.
625 /// </exception>
626 public int Inflate(byte[] buf)
627 {
628 return Inflate(buf, 0, buf.Length);
629 }
630
631 /// <summary>
632 /// Inflates the compressed stream to the output buffer. If this
633 /// returns 0, you should check, whether needsDictionary(),
634 /// needsInput() or finished() returns true, to determine why no
635 /// further output is produced.
636 /// </summary>
637 /// <param name = "buf">
638 /// the output buffer.
639 /// </param>
640 /// <param name = "off">
641 /// the offset into buffer where the output should start.
642 /// </param>
643 /// <param name = "len">
644 /// the maximum length of the output.
645 /// </param>
646 /// <returns>
647 /// the number of bytes written to the buffer, 0 if no further output can be produced.
648 /// </returns>
649 /// <exception cref="System.ArgumentOutOfRangeException">
650 /// if len is &lt;= 0.
651 /// </exception>
652 /// <exception cref="System.ArgumentOutOfRangeException">
653 /// if the off and/or len are wrong.
654 /// </exception>
655 /// <exception cref="System.FormatException">
656 /// if deflated stream is invalid.
657 /// </exception>
658 public int Inflate(byte[] buf, int off, int len)
659 {
660 if (len < 0) {
661 throw new ArgumentOutOfRangeException("len < 0");
662 }
663 // Special case: len may be zero
664 if (len == 0) {
665 if (IsFinished == false) {// -jr- 08-Nov-2003 INFLATE_BUG fix..
666 Decode();
667 }
668 return 0;
669 }
670 /* // Check for correct buff, off, len triple
671 if (off < 0 || off + len >= buf.Length) {
672 throw new ArgumentException("off/len outside buf bounds");
673 }*/
674 int count = 0;
675 int more;
676 do {
677 if (mode != DECODE_CHKSUM) {
678 /* Don't give away any output, if we are waiting for the
679 * checksum in the input stream.
680 *
681 * With this trick we have always:
682 * needsInput() and not finished()
683 * implies more output can be produced.
684 */
685 more = outputWindow.CopyOutput(buf, off, len);
686 adler.Update(buf, off, more);
687 off += more;
688 count += more;
689 totalOut += more;
690 len -= more;
691 if (len == 0) {
692 return count;
693 }
694 }
695 } while (Decode() || (outputWindow.GetAvailable() > 0 && mode != DECODE_CHKSUM));
696 return count;
697 }
698
699 /// <summary>
700 /// Returns true, if the input buffer is empty.
701 /// You should then call setInput().
702 /// NOTE: This method also returns true when the stream is finished.
703 /// </summary>
704 public bool IsNeedingInput {
705 get {
706 return input.IsNeedingInput;
707 }
708 }
709
710 /// <summary>
711 /// Returns true, if a preset dictionary is needed to inflate the input.
712 /// </summary>
713 public bool IsNeedingDictionary {
714 get {
715 return mode == DECODE_DICT && neededBits == 0;
716 }
717 }
718
719 /// <summary>
720 /// Returns true, if the inflater has finished. This means, that no
721 /// input is needed and no output can be produced.
722 /// </summary>
723 public bool IsFinished {
724 get {
725 return mode == FINISHED && outputWindow.GetAvailable() == 0;
726 }
727 }
728
729 /// <summary>
730 /// Gets the adler checksum. This is either the checksum of all
731 /// uncompressed bytes returned by inflate(), or if needsDictionary()
732 /// returns true (and thus no output was yet produced) this is the
733 /// adler checksum of the expected dictionary.
734 /// </summary>
735 /// <returns>
736 /// the adler checksum.
737 /// </returns>
738 public int Adler {
739 get {
740 return IsNeedingDictionary ? readAdler : (int) adler.Value;
741 }
742 }
743
744 /// <summary>
745 /// Gets the total number of output bytes returned by inflate().
746 /// </summary>
747 /// <returns>
748 /// the total number of output bytes.
749 /// </returns>
750 public int TotalOut {
751 get {
752 return totalOut;
753 }
754 }
755
756 /// <summary>
757 /// Gets the total number of processed compressed input bytes.
758 /// </summary>
759 /// <returns>
760 /// the total number of bytes of processed input bytes.
761 /// </returns>
762 public int TotalIn {
763 get {
764 return totalIn - RemainingInput;
765 }
766 }
767
768 /// <summary>
769 /// Gets the number of unprocessed input. Useful, if the end of the
770 /// stream is reached and you want to further process the bytes after
771 /// the deflate stream.
772 /// </summary>
773 /// <returns>
774 /// the number of bytes of the input which were not processed.
775 /// </returns>
776 public int RemainingInput {
777 get {
778 return input.AvailableBytes;
779 }
780 }
781 }
782 }