Exemple #1
0
        public void BzzWriterTest003()
        {
            UTF8Encoding encoding = new UTF8Encoding(false);
            string       filePath = Path.Combine(Util.RepoRoot, "artifacts", "data", "testhello.obz");

            filePath = filePath.Replace(".obz", ".bz3");
            const string testText     = "Hello bzz! \r\n";
            long         bytesWritten = 0;

            using (Stream stream = File.Create(filePath, 8192))
                using (BzzWriter writer = new BzzWriter(stream))
                {
                    // TODO track BzzWriter bug causing side effects during write
                    writer.Write(testText);
                    writer.Flush();

                    bytesWritten = stream.Position;
                }

            byte[] testBuffer = Util.ReadFileToEnd(filePath);
            //byte[] readBuffer = new byte[bytesWritten + 32];
            //Buffer.BlockCopy(testBuffer, 0, readBuffer, 0, (int)bytesWritten);

            using (MemoryStream readStream = new MemoryStream(testBuffer))
                using (BzzReader reader = new BzzReader(new BSInputStream(readStream)))
                {
                    string testResult = reader.ReadUTF8String(testText.Length);
                    Assert.False(String.IsNullOrWhiteSpace(testResult));
                    // Assert.Equal(testText, testResult);
                }
        }
Exemple #2
0
        public void BzzWriterTest001()
        {
            UTF8Encoding encoding = new UTF8Encoding(false);
            string       filePath = Path.Combine(Util.RepoRoot, "artifacts", "data", "testbzznbmont.obz");
            string       testText = File.ReadAllText(filePath, encoding);

            using (MemoryStream stream = new MemoryStream())
                using (BzzWriter writer = new BzzWriter(stream))
                {
                    byte[] buffer = encoding.GetBytes(testText);
                    writer.Write(buffer, 0, buffer.Length);
                    writer.Flush();

                    long bytesWritten = stream.Position;
                    stream.Position = 0;
                    byte[] testBuffer = stream.GetBuffer();
                    byte[] readBuffer = new byte[bytesWritten + 32];
                    Buffer.BlockCopy(testBuffer, 0, readBuffer, 0, (int)bytesWritten);

                    using (MemoryStream readStream = new MemoryStream(readBuffer))
                        using (BzzReader reader = new BzzReader(new BSInputStream(readStream)))
                        {
                            string testResult = reader.ReadUTF8String(buffer.Length);
                            Assert.False(String.IsNullOrWhiteSpace(testResult));
                            // TODO track bug causing roundtrip errors
                            // Assert.Equal(testText, testResult);
                        }
                }
        }
Exemple #3
0
        public void GetBZZEncodedWriterTest1()
        {
            DjvuWriter writer = null;

            using (MemoryStream stream = new MemoryStream())
                using (writer = new DjvuWriter(stream))
                {
                    BzzWriter bzzWriter = null;
                    bzzWriter = writer.GetBZZEncodedWriter();
                    Assert.NotNull(bzzWriter);
                    Assert.IsType <BzzWriter>(bzzWriter);
                }
        }
Exemple #4
0
        public void BzzWriterTest002()
        {
            UTF8Encoding encoding = new UTF8Encoding(false);
            string       filePath = Path.Combine(Util.RepoRoot, "artifacts", "data", "testbzz.obz");
            string       testText = File.ReadAllText(filePath, encoding);

            using (Stream stream = File.Create(filePath.Replace(".obz", ".bz3"), 8192))
                using (BzzWriter writer = new BzzWriter(stream))
                {
                    byte[] buffer = encoding.GetBytes(testText);
                    writer.Write(buffer, 0, buffer.Length);
                    writer.Flush();
                }
        }