Module: Omnizip::Buffer::SevenZipBridge
- Defined in:
- lib/omnizip/buffer/seven_zip_bridge.rb
Overview
Bridges the in-memory Buffer API onto the file-based 7z reader/writer through a temporary file, since the 7z format has no in-memory stream implementation.
Defined Under Namespace
Classes: ReadProxy, WriteProxy
Class Method Summary collapse
-
.create(buffer, options = {}) {|WriteProxy| ... } ⇒ Object
Create a 7z archive in memory.
-
.open(buffer) {|ReadProxy| ... } ⇒ ReadProxy, Object
Read a 7z archive from memory.
Class Method Details
.create(buffer, options = {}) {|WriteProxy| ... } ⇒ Object
Create a 7z archive in memory
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/omnizip/buffer/seven_zip_bridge.rb', line 18 def create(buffer, = {}, &block) Dir.mktmpdir("omnizip_buffer_7z") do |tmp| archive_path = File.join(tmp, "buffer.7z") writer = Formats::SevenZip::Writer.new(archive_path, ) block&.call(WriteProxy.new(writer)) writer.write buffer.write(File.binread(archive_path)) end end |
.open(buffer) {|ReadProxy| ... } ⇒ ReadProxy, Object
Read a 7z archive from memory
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omnizip/buffer/seven_zip_bridge.rb', line 34 def open(buffer, &block) Dir.mktmpdir("omnizip_buffer_7z") do |tmp| archive_path = File.join(tmp, "buffer.7z") File.binwrite(archive_path, buffer.string) reader = Formats::SevenZip::Reader.new(archive_path) reader.open proxy = ReadProxy.new(reader, tmp) block ? yield(proxy) : proxy end end |