Advertisement
gheja

zipping/gzipping binary data vs. base64 encoded data

Sep 16th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. # zipping/gzipping binary data vs. base64 encoded data
  2. # tested on debian squeeze, zip 3.0-3, gzip 1.3.12-9
  3.  
  4. for i in 1 10 100 1024 2048 4096; do
  5. dd if=/dev/urandom of=test_${i}_bin.bin bs=1k count=$i
  6. php -r "file_put_contents('test_${i}_base64.txt', base64_encode(file_get_contents('test_${i}_bin.bin')));"
  7. zip test_${i}_bin.zip test_${i}_bin.bin
  8. zip test_${i}_base64.zip test_${i}_base64.txt
  9. cat test_${i}_bin.bin | gzip -c9 > test_${i}_bin.gz
  10. cat test_${i}_base64.txt | gzip -c9 > test_${i}_base64.gz
  11. ls -alb test_${i}_*
  12. done
  13.  
  14. # formated a bit...
  15.  
  16. 1024 test_1_bin.bin
  17. 1368 test_1_base64.txt
  18. 1202 test_1_bin.zip
  19. 1243 test_1_base64.zip
  20. 1047 test_1_bin.gz
  21. 1077 test_1_base64.gz
  22.  
  23. 10240 test_10_bin.bin
  24. 13656 test_10_base64.txt
  25. 10420 test_10_bin.zip
  26. 10527 test_10_base64.zip
  27. 10263 test_10_bin.gz
  28. 10359 test_10_base64.gz
  29.  
  30. 102400 test_100_bin.bin
  31. 136536 test_100_base64.txt
  32. 102602 test_100_bin.zip
  33. 103513 test_100_base64.zip
  34. 102438 test_100_bin.gz
  35. 103343 test_100_base64.gz
  36.  
  37. 1048576 test_1024_bin.bin
  38. 1398104 test_1024_base64.txt
  39. 1048754 test_1024_bin.gz
  40. 1058208 test_1024_base64.zip
  41. 1048920 test_1024_bin.zip
  42. 1058036 test_1024_base64.gz
  43.  
  44. 2097152 test_2048_bin.bin
  45. 2796204 test_2048_base64.txt
  46. 2097656 test_2048_bin.zip
  47. 2116195 test_2048_base64.zip
  48. 2097490 test_2048_bin.gz
  49. 2116023 test_2048_base64.gz
  50.  
  51. 4194304 test_4096_bin.bin
  52. 5592408 test_4096_base64.txt
  53. 4195128 test_4096_bin.zip
  54. 4232178 test_4096_base64.zip
  55. 4194962 test_4096_bin.gz
  56. 4232006 test_4096_base64.gz
  57.  
  58. # base64 encoded data takes 0.8-2% more space than binary when zipped/gzipped
  59. # note: zipping with "-9" does not make any difference
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement