# Tar archive extract to buffer and offer for view / download

**URL:** <https://www.ruby-forum.com/t/tar-archive-extract-to-buffer-and-offer-for-view-download/189370>\
**Category:** Rails\
**Created:** [May 30, 2010, 2:14am UTC](https://www.ruby-forum.com/t/tar-archive-extract-to-buffer-and-offer-for-view-download/189370 "2010-05-30T02:14:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Togg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/da6949/32.png) [@Togg](https://www.ruby-forum.com/u/Togg)\
**Post date:** [May 30, 2010, 2:14am UTC](https://www.ruby-forum.com/t/tar-archive-extract-to-buffer-and-offer-for-view-download/189370/1 "2010-05-30T02:14:06Z")

</div>

I want to open a tar.gz archive and display the content as a folder  
structure and offer possibility to download and view the content. The  
archive should not be compressed to a folder but only to a buffer.

Helper:  
require ‘tarruby’  
def testFu  
File.directory?(log\_folder) or return “Log folder ‘#{log\_folder}’  
doesn’t exist.”  
log\_archive = File.expand\_path(@log.log\_archive,log\_folder)  
# a hash which i probably can access from my view  
$result = Hash.new  
Tar.gzopen(log\_archive, File::RDONLY, 0644, Tar::GNU |  
Tar::VERBOSE) do |tar|  
tar.each do  
if tar.reg? # regular file  
buf = tar.extract\_buffer  
$result[tar.pathname] = buf  
end  
end  
end  
end

View:

# \<%= File.basename(@log.log\_archive) %\>
 \<% $result.each do |key, value| %\> - \<%= key %\>
 \<% end %\> 

Is my approach rails compliant? How can I add a download link (from  
the buffer) and offer possibilty to view the buffer on click in a  
popup window?

Best regards,  
Sebastian
