public void CngImageReader_ReadBytes_Returns_Number_Bytes_Requested_If_Stream_Contains_Length_Test(byte[] data)
        {
            // Arrange
            var testStream       = new MemoryStream(data);
            var cngReader        = new CngImageReader(testStream);
            var requstedByteSize = 6;

            // Act
            var result = cngReader.ReadBytes(requstedByteSize);

            // Assert
            Assert.Equal(requstedByteSize, result.Length);
        }
        public void CngImageReader_ReadBytes_Returns_Specified_Byte_Length_Data_Test(byte[] data)
        {
            // Arrange
            var testStream = new MemoryStream(data);
            var cngReader  = new CngImageReader(testStream);

            // Act
            var result = cngReader.ReadBytes(8);

            // Assert
            for (var i = 0; i < data.Length; i++)
            {
                Assert.NotEqual(data[i], result[i]);
            }
        }
        public void CngImageReader_ReadBytes_Modifies_Stream_With_Xor_Test()
        {
            // Arrange
            var byteData   = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            var testStream = new MemoryStream(byteData);
            var cngReader  = new CngImageReader(testStream);

            // Act
            var result = cngReader.ReadBytes(8);

            // Assert
            for (var i = 0; i < 8; i++)
            {
                Assert.Equal(byteData[i] ^ CngImageReader.XorValue, result[i]);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            const string inputFile  = @"/media/aaron/CNG_DISC1/disc1/images/199x/19960501/NGM_1996_05_040_4.cng"; //@"E:\NGM_1996_05_001_4.cng";
            const string outputFile = @"outputfile.jpg";

            var fileInfo   = new FileInfo(inputFile);
            var fileLength = fileInfo.Length;

            using (var fs = fileInfo.OpenRead())
            {
                using (var os = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
                {
                    var br = new CngImageReader(fs);

                    var buffer = br.ReadBytes((int)fileLength);
                    var bw     = new BinaryWriter(os);

                    for (var i = 0; i < fileLength; i++)
                    {
                        bw.Write(buffer[i]);
                    }
                }
            }
        }