Extract multiple files from gzip in ruby -


actually have multiple .txt files in .gz file. extract .txt files .gz file... example:

gz_extract = zlib::gzipreader.open("sample.gz") gz_extract.each |extract|   print extract end 

the above code prints whatever present in .gz file want un-gzip .txt files. hope ppl understood question....

actually have multiple .txt files in .gz file. extract .txt files .gz file.

gzip cannot contain multiple files together. works 1 file.

if want compress multiple files, first need tar them together, , gzip resulting .tar file, not appear case file using.

if can read contents of sample.gz code provided, further proof have 1 file inside. can try gunzip sample.gz command-line again prove contains 1 file.

edit:

if want code output uncompressed .txt file:

output_file = file.open('sample.txt', 'w')  gz_extract = zlib::gzipreader.open("sample.gz") gz_extract.each_line |extract|   output_file.write(extract) end  output_file.close 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -