Example #1
0
 // This ctor is private - no validation is done here.  This is to allow the use
 // of a (specific) negative value for the _lengthLimit, to indicate that there
 // is no length set.  So we validate the length limit in those ctors that use an
 // explicit param, otherwise we don't validate, because it could be our special
 // value.
 private CrcCalculatorStream(bool leaveOpen, Int64 length, System.IO.Stream stream)
     : base()
 {
     _innerStream = stream;
     _Crc32 = new CRC32();
     _lengthLimit = length;
     _leaveOpen = leaveOpen;
 }
        private void _DeflateOne(Object wi)
        {
            WorkItem workitem = (WorkItem) wi;
            try
            {
                // compress one buffer
                int myItem = workitem.index;

                lock(workitem)
                {
                    if (workitem.status != (int)WorkItem.Status.Filled)
                        throw new InvalidOperationException();

                    PMDCP.Compression.Zlib.CRC32 crc = new CRC32();

                    // use the workitem:
                    // calc CRC on the buffer
                    crc.SlurpBlock(workitem.buffer, 0, workitem.inputBytesAvailable);

                    // deflate it
                    DeflateOneSegment(workitem);

                    // update status
                    workitem.status = (int)WorkItem.Status.Compressed;
                    workitem.crc = crc.Crc32Result;

                    TraceOutput(TraceBits.Compress,
                                   "Compress          wi({0}) stat({1}) len({2})",
                                   workitem.index,
                                   workitem.status,
                                   workitem.compressedBytesAvailable
                                   );

                    // release the item
                    Monitor.Pulse(workitem);
                }
            }
            catch (System.Exception exc1)
            {
                lock(_eLock)
                {
                    // expose the exception to the main thread
                    if (_pendingException!=null)
                        _pendingException = exc1;
                }
            }
        }