Beispiel #1
0
        /// <summary>
        /// Reads the compressed data from the djvu file
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="count"></param>
        /// <param name="compressedSectionLength"></param>
        internal void ReadCompressedData(IDjvuReader reader, int count, int compressedSectionLength)
        {
            long prevPos = reader.Position;

            BzzReader bzReader = reader.GetBZZEncodedReader(compressedSectionLength);

            // Read the component sizes
            for (int x = 0; x < count; x++)
            {
                _components[x].Size = bzReader.ReadInt24BigEndian();
            }

            // Read the component flag information
            for (int x = 0; x < count; x++)
            {
                _components[x].DecodeFlags(bzReader.ReadByte());
            }

            // Read the component strings
            for (int x = 0; x < count; x++)
            {
                _components[x].ID = bzReader.ReadNullTerminatedString();
                if (_components[x].HasName == true)
                {
                    _components[x].Name = bzReader.ReadNullTerminatedString();
                }

                if (_components[x].HasTitle == true)
                {
                    _components[x].Title = bzReader.ReadNullTerminatedString();
                }
            }

            _isInitialized = true;

            reader.Position = prevPos;
        }
Beispiel #2
0
        public void ReadNullTerminatedStringTest()
        {
            string filePath = Path.Combine(Util.ArtifactsDataPath, "testbzznbmont.bz");
            string testPath = Path.Combine(Util.ArtifactsDataPath, "testbzznbmont.obz");

            byte[] sourceBuffer = Util.ReadFileToEnd(filePath);
            byte[] testBuffer   = Util.ReadFileToEnd(testPath);
            using (MemoryStream readStream = new MemoryStream(sourceBuffer))
                using (BzzReader reader = new BzzReader(new BSInputStream(readStream)))
                {
                    string expected   = new UTF8Encoding(false).GetString(testBuffer, 0, testBuffer.Length - 1);
                    string testResult = reader.ReadNullTerminatedString();
                    Assert.False(String.IsNullOrWhiteSpace(testResult));
                    Assert.Equal <int>(expected.Length, testResult.Length);
                    Assert.Equal(expected, testResult);
                }
        }