title: create smaller chunks of a file then compress and decompress back into one file
body: <p>I'm trying to create a file transfer application which sends files after compressing them. My main goal was to provide resumable transfer with it, for that purpose, I first create an archive of all the files the user has to send, then I open the archive in a stream and read a chunk of data from it (say a chunk of 2mb), I compress that chunk and decompress it on the receiving side and then append that data into a larger file which will become the main archive.</p>
  
  <pre><code>GZipOutputStream gzipout = new GZipOutputStream(File.Create("abc.zip"));
                  //reading and compressing the chunk into abc.zip
                  do
                  {
                      //f is my filestream for the original archive
                      sourceBytes = f.Read(buffer, 0, buffer.Length);
                      if (sourceBytes == 0)
                      {
                          break;
                      }
                      gzipout.Write(buffer, 0, sourceBytes);
                      bytesread += sourceBytes;
                  } while (bytesread &lt; chunklength);
              bytesread = 0;
  
  
  
              gzipout.Finish();
              gzipout.Close();
              //encrypting the chunk
              s.EncryptFile("abc.zip","abc.enc");
  
              //the chunk is sent over here to the receiving side
              //these are the functions on the receiving side
              //decrypting the chunk
              s.DecryptFile("abc.enc","abc1.zip");
  
              GZipInputStream gzipin=new GZipInputStream(File.OpenRead("abc1.zip"));
              //the chunk is being decompressed and appended into the original archive file
              FileStream temp = File.Open(Path.GetFileName("originalzip.zip"), FileMode.Append);
  
              int size = 2048;
              byte[] data = new byte[2048];
              while (true)
              {
                  size = gzipin.Read(data, 0, data.Length);
                  if (size != 0)
                      temp.Write(data, 0, size);
                  else
                      break;
              }
              temp.Flush();
              temp.Close();
          } while (sourceBytes!=0);
          ExtractAll("originalzip.zip", "testest");
  </code></pre>
  
  <p>The problem is somewhere in the chunking process because if i send the archive as it is, it works, but when i try to make chunks, the receiving archive has a larger size and can't be opened.</p>
  
  <p>Edit: It's fixed, i deleted the previously created chunk before making the new one and it fixed it</p>