Class: Cabriolet::LIT::Compressor
- Inherits:
-
Object
- Object
- Cabriolet::LIT::Compressor
- Defined in:
- lib/cabriolet/lit/compressor.rb
Overview
Compressor creates LIT eBook files
LIT files are Microsoft Reader eBook files that use LZX compression. The compressor allows adding multiple files to create a LIT archive.
NOTE: This implementation creates non-encrypted LIT files only. DES encryption (DRM protection) is not implemented.
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#io_system ⇒ Object
readonly
Returns the value of attribute io_system.
Instance Method Summary collapse
-
#add_file(source_path, lit_path, **options) ⇒ void
Add a file to the LIT archive.
-
#generate(output_file, **options) ⇒ Integer
Generate the LIT archive.
-
#initialize(io_system = nil, algorithm_factory = nil) ⇒ Compressor
constructor
Initialize a new LIT compressor.
Constructor Details
#initialize(io_system = nil, algorithm_factory = nil) ⇒ Compressor
Initialize a new LIT compressor
27 28 29 30 31 |
# File 'lib/cabriolet/lit/compressor.rb', line 27 def initialize(io_system = nil, algorithm_factory = nil) @io_system = io_system || System::IOSystem.new @algorithm_factory = algorithm_factory || Cabriolet.algorithm_factory @files = [] end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
21 22 23 |
# File 'lib/cabriolet/lit/compressor.rb', line 21 def files @files end |
#io_system ⇒ Object (readonly)
Returns the value of attribute io_system.
21 22 23 |
# File 'lib/cabriolet/lit/compressor.rb', line 21 def io_system @io_system end |
Instance Method Details
#add_file(source_path, lit_path, **options) ⇒ void
This method returns an undefined value.
Add a file to the LIT archive
40 41 42 43 44 45 46 47 48 |
# File 'lib/cabriolet/lit/compressor.rb', line 40 def add_file(source_path, lit_path, **) compress = .fetch(:compress, true) @files << { source: source_path, lit_path: lit_path, compress: compress, } end |
#generate(output_file, **options) ⇒ Integer
Generate the LIT archive
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cabriolet/lit/compressor.rb', line 59 def generate(output_file, **) version = .fetch(:version, 1) language_id = .fetch(:language_id, 0x409) creator_id = .fetch(:creator_id, 0) raise ArgumentError, "No files added to archive" if @files.empty? raise ArgumentError, "Version must be 1" unless version == 1 # Prepare file data file_data = prepare_files # Build LIT structure structure_builder = StructureBuilder.new( io_system: @io_system, version: version, language_id: language_id, creator_id: creator_id, ) lit_structure = structure_builder.build(file_data) # Write to output file output_handle = @io_system.open(output_file, Constants::MODE_WRITE) begin bytes_written = write_lit_file(output_handle, lit_structure) bytes_written ensure @io_system.close(output_handle) end end |