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
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) ⇒ Compressor
constructor
Initialize a new LIT compressor.
Constructor Details
#initialize(io_system = nil) ⇒ Compressor
Initialize a new LIT compressor
20 21 22 23 |
# File 'lib/cabriolet/lit/compressor.rb', line 20 def initialize(io_system = nil) @io_system = io_system || System::IOSystem.new @files = [] end |
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
14 15 16 |
# File 'lib/cabriolet/lit/compressor.rb', line 14 def files @files end |
#io_system ⇒ Object (readonly)
Returns the value of attribute io_system.
13 14 15 |
# File 'lib/cabriolet/lit/compressor.rb', line 13 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
33 34 35 36 37 38 39 40 41 |
# File 'lib/cabriolet/lit/compressor.rb', line 33 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
53 54 55 56 57 58 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 88 89 90 91 |
# File 'lib/cabriolet/lit/compressor.rb', line 53 def generate(output_file, **) version = .fetch(:version, 1) encrypt = .fetch(:encrypt, false) if encrypt raise NotImplementedError, "DES encryption is not implemented. " \ "LIT files will be created without encryption." end raise ArgumentError, "No files added to archive" if @files.empty? output_handle = @io_system.open(output_file, Constants::MODE_WRITE) begin # Prepare file data file_data = prepare_files # Write header header_bytes = write_header( output_handle, version, file_data.size, ) # Write file entries entries_bytes = write_file_entries(output_handle, file_data) # Write file contents content_bytes = write_file_contents( output_handle, file_data, ) header_bytes + entries_bytes + content_bytes ensure @io_system.close(output_handle) if output_handle end end |