【发布时间】:2015-11-24 16:44:08
【问题描述】:
我正在尝试创建一个显示 zip 文件内容的表格,如下所示:
Name Size
asdf1.jpg 100KB
asdf2.jpg 200KB
asdf3.jpg 300KB
我的代码在这里(实际上,我是从 ZipRuby 的 README 中复制的):
#myapp.rb
post 'checkfile/?' do
Zip::Archive.open('zip_file.zip') do |ar|
n = ar.num_files
n.times do |i|
entry_name = ar.get_name(i) # get entry name from archive
# open entry
ar.fopen(entry_name) do |f| # or ar.fopen(i) do |f|
$name = f.name # name of the file
$size = f.size # size of file (uncompressed)
$comp_size = f.comp_size # size of file (compressed)
content = f.read # read entry content
end
end
# Zip::Archive includes Enumerable
entry_names = ar.map do |f|
f.name
end
end
haml :checkresult
end
还有我的haml代码:
-# checkresult.haml
%table
%thead
%tr
%th Name
%th Size
%tbody
%tr
-# I want to show files in zip here
抱歉英语不好,标题不好。 (使用 Sinatra v1.4.6(与 Puma)。)
【问题讨论】:
-
你确定你使用的是
Ruby on Rails吗?您能否确认您正在使用的 Web 框架? -
使用 Sinatra v1.4.6(与 Puma 一起)。感谢 cmets! :)
标签: ruby-on-rails ruby sinatra haml