CrcCalculatorStream usage

Feb 5, 2014 at 2:01 AM
As part of an interop project we've been tasked with calculating the crc32 on a file that we deliver to an ftp drop box. I'm trying to use the CrcCalculatorStream to do so. However, I'm clearly doing something wrong because the crc32 I've been getting is a negative value. Below is some sample code that mirrors the way in which I'm using the CrcCalculatorStream class.

The questions are
  • am I using the CrcCalculatorClass properly to calculate the final CRC32 on the file?
  • why am I getting negative CRC values from the CrcCalculatorClass.CRC property?
public class CRCFileWriter
        private FileStream _writer;
        private CrcCalculatorStream _crcStream;

        public CRCFileWriter(string filename)
            _writer = new FileStream(filename, FileMode.Create);
            _crcStream = new CrcCalculatorStream(_writer);

        public void WriteToFile(byte[] bytes, int numberToWrite)
            _crcStream.Write(bytes, 0, numberToWrite);

        public int GetCRC()
            int crc = _crcStream.Crc;

            return crc;