Class: Cabriolet::LIT::CommandHandler
- Inherits:
-
Commands::BaseCommandHandler
- Object
- Commands::BaseCommandHandler
- Cabriolet::LIT::CommandHandler
- Defined in:
- lib/cabriolet/lit/command_handler.rb
Overview
Command handler for LIT (Microsoft Reader eBook) format
This handler implements the unified command interface for LIT files, wrapping the existing LIT::Decompressor and LIT::Compressor classes. LIT files use LZX compression and may include DRM protection.
Instance Method Summary collapse
-
#create(output, files = [], options = {}) ⇒ void
Create a new LIT archive.
-
#extract(file, output_dir = nil, options = {}) ⇒ void
Extract files from LIT archive.
-
#info(file, _options = {}) ⇒ void
Display detailed LIT file information.
-
#list(file, options = {}) ⇒ void
List LIT file contents.
-
#test(file, _options = {}) ⇒ void
Test LIT file integrity.
Methods inherited from Commands::BaseCommandHandler
Constructor Details
This class inherits a constructor from Cabriolet::Commands::BaseCommandHandler
Instance Method Details
#create(output, files = [], options = {}) ⇒ void
This method returns an undefined value.
Create a new LIT archive
Creates a LIT file from HTML source files. Non-encrypted LIT files are created (DRM not supported).
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cabriolet/lit/command_handler.rb', line 76 def create(output, files = [], = {}) raise ArgumentError, "No files specified" if files.empty? files.each do |f| raise ArgumentError, "File does not exist: #{f}" unless File.exist?(f) end language_id = [:language_id] || 0x409 version = [:version] || 1 compressor = Compressor.new files.each do |f| # Default to adding with compression lit_path = "/#{File.basename(f)}" compressor.add_file(f, lit_path, compress: true) end puts "Creating #{output} with #{files.size} file(s) (v#{version}, lang: 0x#{Integer(language_id).to_s(16)})" if verbose? bytes = compressor.generate(output, version: version, language_id: language_id) puts "Created #{output} (#{bytes} bytes, #{files.size} files)" end |
#extract(file, output_dir = nil, options = {}) ⇒ void
This method returns an undefined value.
Extract files from LIT archive
Extracts all files from the LIT file to the specified output directory. Uses manifest for filename restoration if available.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cabriolet/lit/command_handler.rb', line 47 def extract(file, output_dir = nil, = {}) validate_file_exists(file) output_dir ||= "." output_dir = ensure_output_dir(output_dir) decompressor = Decompressor.new lit_file = decompressor.open(file) use_manifest = .fetch(:use_manifest, true) count = decompressor.extract_all(lit_file, output_dir, use_manifest: use_manifest) decompressor.close(lit_file) puts "Extracted #{count} file(s) to #{output_dir}" end |
#info(file, _options = {}) ⇒ void
This method returns an undefined value.
Display detailed LIT file information
Shows comprehensive information about the LIT structure, including sections, manifest, and files.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cabriolet/lit/command_handler.rb', line 107 def info(file, = {}) validate_file_exists(file) decompressor = Decompressor.new lit_file = decompressor.open(file) display_lit_info(lit_file) decompressor.close(lit_file) end |
#list(file, options = {}) ⇒ void
This method returns an undefined value.
List LIT file contents
Displays information about the LIT file including version, language, and lists all contained files with their sizes.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/cabriolet/lit/command_handler.rb', line 25 def list(file, = {}) validate_file_exists(file) decompressor = Decompressor.new lit_file = decompressor.open(file) display_header(lit_file) display_files(lit_file, decompressor, ) decompressor.close(lit_file) end |
#test(file, _options = {}) ⇒ void
This method returns an undefined value.
Test LIT file integrity
Verifies the LIT file structure.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/cabriolet/lit/command_handler.rb', line 125 def test(file, = {}) validate_file_exists(file) decompressor = Decompressor.new lit_file = decompressor.open(file) puts "Testing #{file}..." # Check for DRM if lit_file.encrypted? puts "WARNING: LIT file is DRM-encrypted (level: #{lit_file.drm_level})" puts "Encryption is not supported by this implementation" else puts "OK: LIT file structure is valid (#{lit_file.directory.entries.size} files)" end decompressor.close(lit_file) end |