Class: Omnizip::ArchiveHandlers::RarHandler::WriterProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/archive_handlers/rar_handler.rb

Overview

Translates the generic add(name, source_path) / add_data(name, data) / add_directory(name) interface onto the RAR writers. The writers take file paths, so in-memory content spills to a temporary file.

Instance Method Summary collapse

Constructor Details

#initialize(writer) ⇒ WriterProxy

Returns a new instance of WriterProxy.



60
61
62
63
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 60

def initialize(writer)
  @writer = writer
  @spill = []
end

Instance Method Details

#add(name, source_path = nil) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 65

def add(name, source_path = nil)
  if source_path
    @writer.add_file(source_path, name)
  else
    @writer.add_directory_entry(name)
  end
end

#add_data(name, data) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 73

def add_data(name, data)
  file = Tempfile.new(["omnizip_rar_entry", File.extname(name)])
  file.binmode
  file.write(data)
  file.close
  @spill << file
  @writer.add_file(file.path, name)
end

#add_directory(name) ⇒ Object



82
83
84
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 82

def add_directory(name)
  @writer.add_directory_entry(name)
end

#cleanupObject

Remove the temporary files add_data spilled



87
88
89
90
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 87

def cleanup
  @spill.each(&:unlink)
  @spill.clear
end