Class: Omnizip::Formats::Rar::Writer
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Writer
- Includes:
- Constants
- Defined in:
- lib/omnizip/formats/rar/writer.rb
Overview
Pure Ruby RAR archive writer
This class provides basic RAR archive creation in pure Ruby. It writes RAR4-compatible archives with basic compression support.
Constant Summary
Constants included from Constants
Constants::ARCHIVE_AUTH_INFO, Constants::ARCHIVE_COMMENT, Constants::ARCHIVE_ENCRYPTED, Constants::ARCHIVE_FIRST_VOLUME, Constants::ARCHIVE_LOCKED, Constants::ARCHIVE_NEW_NAMING, Constants::ARCHIVE_RECOVERY, Constants::ARCHIVE_SOLID, Constants::ARCHIVE_VOLUME, Constants::BLOCK_ARCHIVE, Constants::BLOCK_COMMENT, Constants::BLOCK_ENDARC, Constants::BLOCK_FILE, Constants::BLOCK_MARKER, Constants::BLOCK_OLD_AUTH, Constants::BLOCK_OLD_EXTRA, Constants::BLOCK_OLD_RECOVERY, Constants::BLOCK_OLD_SUBBLOCK, Constants::BLOCK_SUBBLOCK, Constants::FILE_COMMENT, Constants::FILE_DIRECTORY, Constants::FILE_ENCRYPTED, Constants::FILE_EXT_TIME, Constants::FILE_LARGE, Constants::FILE_SALT, Constants::FILE_SOLID, Constants::FILE_SPLIT_AFTER, Constants::FILE_SPLIT_BEFORE, Constants::FILE_UNICODE, Constants::FILE_VERSION, Constants::METHOD_BEST, Constants::METHOD_FAST, Constants::METHOD_FASTEST, Constants::METHOD_GOOD, Constants::METHOD_NORMAL, Constants::METHOD_STORE, Constants::OS_BEOS, Constants::OS_MACOS, Constants::OS_MSDOS, Constants::OS_OS2, Constants::OS_UNIX, Constants::OS_WIN32, Constants::RAR4_SIGNATURE, Constants::RAR5_FLAG_CHILD_BLOCKS, Constants::RAR5_FLAG_DATA_AREA, Constants::RAR5_FLAG_DATA_INHERITED, Constants::RAR5_FLAG_EXTRA_AREA, Constants::RAR5_FLAG_IS_DIR, Constants::RAR5_FLAG_MULTI_VOLUME, Constants::RAR5_FLAG_UNKNOWN_BLOCKS, Constants::RAR5_HEADER_ENCRYPTION, Constants::RAR5_HEADER_END, Constants::RAR5_HEADER_FILE, Constants::RAR5_HEADER_MAIN, Constants::RAR5_HEADER_SERVICE, Constants::RAR5_SIGNATURE
Instance Attribute Summary collapse
-
#directories ⇒ Array<Hash>
readonly
Directories to add.
-
#files ⇒ Array<Hash>
readonly
Files to add.
-
#options ⇒ Hash
readonly
Compression options.
-
#output_path ⇒ String
readonly
Output archive path.
Class Method Summary collapse
-
.available? ⇒ Boolean
Check if RAR creation is available.
-
.info ⇒ Hash
Get RAR writer information.
Instance Method Summary collapse
-
#add_directory(dir_path, recursive: true, archive_path: nil) ⇒ Object
Add directory to archive.
-
#add_file(file_path, archive_path = nil) ⇒ Object
Add file to archive.
-
#initialize(output_path, options = {}) ⇒ Writer
constructor
Initialize RAR writer.
-
#write ⇒ String
Create RAR archive.
Constructor Details
#initialize(output_path, options = {}) ⇒ Writer
Initialize RAR writer
72 73 74 75 76 77 |
# File 'lib/omnizip/formats/rar/writer.rb', line 72 def initialize(output_path, = {}) @output_path = output_path @options = .merge() @files = [] @directories = [] end |
Instance Attribute Details
#directories ⇒ Array<Hash> (readonly)
Returns Directories to add.
40 41 42 |
# File 'lib/omnizip/formats/rar/writer.rb', line 40 def directories @directories end |
#files ⇒ Array<Hash> (readonly)
Returns Files to add.
37 38 39 |
# File 'lib/omnizip/formats/rar/writer.rb', line 37 def files @files end |
#options ⇒ Hash (readonly)
Returns Compression options.
34 35 36 |
# File 'lib/omnizip/formats/rar/writer.rb', line 34 def @options end |
#output_path ⇒ String (readonly)
Returns Output archive path.
31 32 33 |
# File 'lib/omnizip/formats/rar/writer.rb', line 31 def output_path @output_path end |
Class Method Details
.available? ⇒ Boolean
Check if RAR creation is available
45 46 47 |
# File 'lib/omnizip/formats/rar/writer.rb', line 45 def self.available? true end |
.info ⇒ Hash
Get RAR writer information
52 53 54 55 56 57 58 |
# File 'lib/omnizip/formats/rar/writer.rb', line 52 def self.info { available: true, type: :pure_ruby, version: "4.0", } end |
Instance Method Details
#add_directory(dir_path, recursive: true, archive_path: nil) ⇒ Object
Add directory to archive
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/omnizip/formats/rar/writer.rb', line 100 def add_directory(dir_path, recursive: true, archive_path: nil) raise ArgumentError, "Directory not found: #{dir_path}" unless Dir.exist?(dir_path) @directories << { source: File.(dir_path), recursive: recursive, archive_path: archive_path, } end |
#add_file(file_path, archive_path = nil) ⇒ Object
Add file to archive
84 85 86 87 88 89 90 91 92 |
# File 'lib/omnizip/formats/rar/writer.rb', line 84 def add_file(file_path, archive_path = nil) raise ArgumentError, "File not found: #{file_path}" unless File.exist?(file_path) @files << { source: File.(file_path), archive_path: archive_path, } end |
#write ⇒ String
Create RAR archive
114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/omnizip/formats/rar/writer.rb', line 114 def write File.open(@output_path, "wb") do |io| write_signature(io) write_marker_block(io) write_archive_header(io) write_file_entries(io) write_end_block(io) end # Test archive if requested test_archive if @options[:test_after_create] @output_path end |