I want to write big size string to gzip file, because the string length have a limit , so I cut the string to multi substring, then write substring to gz file seperately, but the gz file is a little bigger.
I make a demo
write2gzfile.cr to show the different like this:
require "gzip" aa = "AB"*100 bb = "12"*100 # write to gzip file with one time gzio = File.open("./fileaabb.gz", "w") write2gz(gzio, aa+"\n"+bb) gzio.close # write the same content to gzip file with two times gzio = File.open("./fileaa.bb.gz", "w") write2gz(gzio, aa) write2gz(gzio, bb) gzio.close def write2gz(io : IO, content = "") Gzip::Writer.open(io) do |gzip| gzip.puts(content) end end
after build, then run get this two files:
$ ls -l file*gz -rw-r--r-- 1 root root 31 Dec 19 21:46 fileaabb.gz -rw-r--r-- 1 root root 52 Dec 19 21:46 fileaa.bb.gz
fileaabb.gz file is 31 bytes, but
fileaa.bb.gz is 52 bytes.
If the size of content which wait for writing is more big, the size different of gz file after writing maybe more big.
So I want to make the gz file after writing is smaller as possible, how can I do that?