Hi!

I'm making a program that uploads my game to an Ftp server but when the data is compressed something goes wrong and I end up with an array of zeroes.

Here's my code:

FileStream filestream = File.OpenRead(file);
                    byte[] filebyte = new byte[filestream.Length];
                    filestream.Read(filebyte, 0, filebyte.Length);
                    filestream.Close();

                    //MemoryStream inS = new MemoryStream(filebyte);
                    MemoryStream outS = new MemoryStream();

                    GZipStream gzip = new GZipStream(outS, CompressionMode.Compress, true);
                    //inS.CopyTo((Stream)gzip);
                    gzip.Write(filebyte, 0, filebyte.Length);
                    gzip.Close();
                    
                    byte[] compressed = new byte[outS.Length];
                    outS.Read(compressed, 0, compressed.Length);
                    outS.Close();

Please help!

When you attempt to read from the MemoryStream, it is pointing at the end of the buffer. Reset the pointer to the start of the MemoryStream buffer before reading outS.Seek(0, SeekOrigin.Begin);

Thanks worked like a charm :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.