0

I have the following csv file: https://dl.dropboxusercontent.com/u/8518063/ShareX/2016/03/simple.csv

I use windows explorer to "send to compressed zip folder" and get this file: https://dl.dropboxusercontent.com/u/8518063/ShareX/2016/03/simple.zip

I use http://www.motobit.com/util/base64-decoder-encoder.asp and upload the zip folder and get this base64encoded string: UEsDBBQAAAAIAMB5fEhJO+GGVQAAAIoAAAAKAAAAc2ltcGxlLmNzdk3KOwqAMBRE0V5wJzHk/ZPl CIoIQZu4f/Ms1FsMU5x6HtvermUNdW7PGYcJAGIBoISoVrxAFMkQWRVy6pn9nHFhcCavMyBxp/o5 xiw5uePXlb7uRG9QSwECFAAUAAAACADAeXxISTvhhlUAAACKAAAACgAAAAAAAAABACAAAAAAAAAA c2ltcGxlLmNzdlBLBQYAAAAAAQABADgAAAB9AAAAAAA=

I am unable to reproduce the base64string using c#. My attempt:

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.IO.Compression;
var csv = @"longitude,latitude
-111.91130226799999,33.372246618000077
-111.91137494199995,33.372247135000066
-111.91142858099994,33.372249372000056";
Console.WriteLine(Convert.ToBase64String(Zip(csv)));

        public static byte[] Zip(string str)
        {
            var bytes = Encoding.UTF8.GetBytes(str);
            using (var msi = new MemoryStream(bytes))
            {
                using (var mso = new MemoryStream())
                {
                    using (var gs = new GZipStream(mso, CompressionMode.Compress))
                    {
                        msi.CopyTo(gs);
                    }
                    return mso.ToArray();
                }
            }
        }

Runnable online here: http://csharppad.com/gist/e5d92798cb4a9c7887d6

returns H4sIAAAAAAAEAEXKOwqAMBBF0d61xJD5Z5YjKCIEbeL+dSziLR6vOO0696Pf65ba0r8zzQCQHYAKoppHiSiTIbIq1PJm9jNjZwglgxmQBFMdjLFKLcF4MH83mOgD8gxr24cAAAA=

Kraang Prime
  • 9,981
  • 10
  • 58
  • 124
LearningJrDev
  • 911
  • 2
  • 8
  • 27
  • It does not matter if compressed data matched, is the source data can be decompressed right? – gabba Mar 28 '16 at 21:11
  • You have, like the OP of the marked duplicate, confused a gzip stream, which is a single compressed stream of bytes, with a ZIP archive, which is a structured file format that can act as a container for multiple files and folders. If you want to achieve the same effect as "Send to compressed..." in Windows, you need `ZipArchive`, not `GZipStream`. Note that even so, you _still_ may not generate the exact same bytes (and hence exact same base64 text), because you are dealing with two completely different ZIP archive implementations; The archives will be equivalent, but may not be identical. – Peter Duniho Mar 29 '16 at 02:01

0 Answers0