For 1 specific file I get wrong data after char 813302

3 posts, 0 answers
  1. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 14 Mar 2014 Link to this post

    For 1 specific file I get wrong data after char 813302

    It doesnt seem related to the size of the file, larger files work fine.

    I do have an example that reproduces this, but so far I have only been able to reproduce it with sensitive data.

    After compressing/decompressing I get:
    <Field Name="Datum wijziging" Type="2" Length="0" FieldName="MUT_DAT" Hint="Datum van de laatste wijziging" RowAANdh="0" FieldName="CREATOR_ID" Hint="Creator_id" />
    <Field Name="Datum aanmaak" Type="2" Length="0" FieldName="CREATEDATE" Hint="Createdate" />

    In the original it said:
    <Field Name="Datum aanmaak" Type="2" Length="0" FieldName="CREATEDATE" Hint="Createdate" />
    <Field Name="Datum wijziging" Type="2" Length="0" FieldName="MUT_DAT" Hint="Datum van de laatste wijziging" RowGroup="88" />

    So the two Field are swapped, also there is some strange tag RowAANdh in it that I cant explain, it looks like the RowGroup="88"

    The code I use is below

    The output I get is:

    Loading file: ..\..\PowerBrowser.gpf
    Length original: 5691434
    Length after compress/decompress: 5657083
    Index first difference: 813302 



    using System.Windows;
    using System.Xml.Linq;
    using System;
    using System.IO;
    using Telerik.Windows.Zip;
     
    namespace TelerikTest
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
                DataContext = this;
     
     
            }
            public static byte[] Compress(string text)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    using (ZipOutputStream zipOutputStream = new ZipOutputStream(memoryStream, ZipCompression.Deflated))
                    {
                        using (StreamWriter streamWriter = new StreamWriter(zipOutputStream))
                        {
                            streamWriter.Write(text);
                            //streamWriter.Flush();
                        }
                        byte[] bytes = memoryStream.ToArray();
                        return bytes;
                    }
                }
            }
            public static string Decompress(byte[] data)
            {
                using (MemoryStream memoryStream = new MemoryStream(data))
                {
                    using (ZipInputStream zipInputStream = new ZipInputStream(memoryStream))
                    {
                        using (StreamReader streamReader = new StreamReader(zipInputStream, new System.Text.UTF8Encoding()))
                        {
                            string text = streamReader.ReadToEnd();
                            return text;
                        }
                    }
                }
            }
     
            private void Button_Click(object sender, RoutedEventArgs e)
            {
                MainLog.AppendText(string.Format("Loading file: {0}\n", FileTextBox.Text));
                XElement xml = XElement.Load(FileTextBox.Text);
                string text = xml.ToString();
                MainLog.AppendText(string.Format("Length original: {0}\n", text.Length));
                byte[] c = Compress(text);
                string text2 = Decompress(c);
                File.WriteAllText(@"..\..\OutputFromTelerikTest.gpf", text2);
                MainLog.AppendText(string.Format("Length after compress/decompress: {0}\n", text2.Length));
                int indexFirstDifference = -1;
                for (int i = 0; i < Math.Min(text.Length, text2.Length); i++)
                {
                    if (text[i] != text2[i])
                    {
                        indexFirstDifference = i;
                        break;
                    }
                }
                MainLog.AppendText(string.Format("Index first difference: {0}\n", indexFirstDifference));
                MainLog.AppendText("\n");
            }
        }
    }











  2. B
    B avatar
    74 posts
    Member since:
    Jul 2011

    Posted 14 Mar 2014 Link to this post

    Ok, looks like it does work when I use ZipArchive and make a zip archive with a file in it.
    public static byte[] Compress2(string text)
    {
        using (MemoryStream stream = new MemoryStream())
        {
            using (ZipArchive archive = new ZipArchive(stream, ZipArchiveMode.Create, false, null))
            {
                using (ZipArchiveEntry entry = archive.CreateEntry("x"))
                {
                    using (StreamWriter sw = new StreamWriter(entry.Open()))
                    {
                        sw.Write(text);
                    }
                }
            }
            byte[] bytes = stream.ToArray();
            return bytes;
        }
    }
    private string Decompress2(byte[] data)
    {
        using (MemoryStream memoryStream = new MemoryStream(data))
        {
            using (ZipArchive archive = new ZipArchive(memoryStream, ZipArchiveMode.Read, false, null))
            {
                using (ZipArchiveEntry entry = archive.GetEntry("x"))
                {
                    using (StreamReader sr = new StreamReader(entry.Open()))
                    {
                        return sr.ReadToEnd();
                    }
                }
            }
        }
    }
  3. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 17 Mar 2014 Link to this post

    Hello,

    It is very complicated and it is hard to reproduce the problem without the file you use, but using just a code snippet you sent. We have checked compression/decompression functionality using a few xml files with length between 3 and 50 Mb, but it worked just fine.

    It looks the problem does not occurs for your specific file when you use the ZipArchive just because by default the ZipArchive uses compression level different than ZipCompression.Deflated.
    Could you, please, create a support ticket and attach a file you use? By doing so we will be able to further investigate the reasons behind the issue.

    Thank you for your cooperation.

    Regards,
    Andrey Murzov
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
Back to Top