Ruby - 使用 Mechanize::File 响应而不保存到磁盘
我正在开发我的第一个 ORM 项目并使用 Mechanize。情况如下:
我正在从我的网站下载一个 zip 文件到 Mechanize::File 对象中。 zip 内有一个文件,深埋三个文件夹 (folder_1/folder_2/file.txt)。我想从 zip 文件中提取 file.txt 并返回它而不是 zip 文件本身。
我的第一个想法是使用 zip/zip 文件系统。如果我先将文件保存到磁盘并使用 Zip::ZipFile.open(src) 我可以做到这一点,但是任何人都可以告诉我如何/是否可以直接从 Mechanize::File.body 发送它。
我的直觉告诉我这一定是可能的,但我只是错过了一些基本的东西。我尝试过......
zipfile = Mechanize::File.body
Zip::ZipFile.open(zipfile)
但据我所知,Zip::ZipFile 仅设置为从文件系统中查找源。
任何指示将不胜感激,如果有任何问题请告诉我
提前致谢 抢
I'm working on my first ORM project and am using Mechanize. Here's the situation:
I'm downloading a zip file from my website into a Mechanize::File object. Inside the zip is a file buried three folders deep (folder_1/folder_2/file.txt). I'd like to pull file.txt out of the zip file and return that instead of the zip file itself.
My first thought was to use zip/zipfilesystem. I can do this fine if I save the file to the disk first and use Zip::ZipFile.open(src) but can anyone tell me how/if it is possible to send it over straight from the Mechanize::File.body.
My gut says this has to be possible and I'm just missing something basic. I tried...
zipfile = Mechanize::File.body
Zip::ZipFile.open(zipfile)
...but from what I can tell Zip::ZipFile is only set up to locate a source from a filesystem.
Any direction would be very appreciated and let me know if there are any questions
Thanks in advance
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来你想做的事用 rubyzip 是不可能的。来自 rubyzip 库的 TODO 文件:
It seems what you want to do is not possible with rubyzip. From rubyzip library's TODO file: