code_junkie

File Compressed by GZIP grows instead of shrinking

Nov 13th, 2011
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. Public Sub Compress(ByVal infile As String, ByVal outfile As String)
  2. Dim sourceFile As FileStream = File.OpenRead(inFile)
  3. Dim destFile As FileStream = File.Create(outfile)
  4.  
  5. Dim compStream As New GZipStream(destFile, CompressionMode.Compress)
  6.  
  7. Dim myByte As Integer = sourceFile.ReadByte()
  8. While myByte <> -1
  9. compStream.WriteByte(CType(myByte, Byte))
  10. myByte = sourceFile.ReadByte()
  11. End While
  12.  
  13. sourceFile.Close()
  14. destFile.Close()
  15. End Sub
  16.  
  17. FileStream sourceFile;
  18. GZipStream compStream;
  19.  
  20. byte[] buffer = new byte[65536];
  21. int bytesRead = 0;
  22. while (bytesRead = sourceFile.Read(buffer, 0, 65536) > 0)
  23. {
  24. compStream.Write(buffer, 0, bytesRead);
  25. }
Add Comment
Please, Sign In to add comment