Class: Cabriolet::Models::SZDDHeader
- Inherits:
-
Object
- Object
- Cabriolet::Models::SZDDHeader
- Defined in:
- lib/cabriolet/models/szdd_header.rb
Overview
Represents an SZDD file header
SZDD files are single-file compressed archives using LZSS compression. They were commonly used with MS-DOS COMPRESS.EXE and EXPAND.EXE commands.
Constant Summary collapse
- FORMAT_NORMAL =
SZDD format types
:normal- FORMAT_QBASIC =
:qbasic
Instance Attribute Summary collapse
-
#filename ⇒ String?
Original or suggested filename.
-
#format ⇒ Symbol
Format of the SZDD file (:normal or :qbasic).
-
#length ⇒ Integer
Uncompressed file size in bytes.
-
#missing_char ⇒ String?
Missing character from the original filename (NORMAL format only) Commonly the last character (e.g., ‘t’ in ‘file.txt’ -> ‘file.tx_’).
Instance Method Summary collapse
-
#initialize(format: FORMAT_NORMAL, length: 0, missing_char: nil, filename: nil) ⇒ SZDDHeader
constructor
Initialize a new SZDD header.
-
#normal_format? ⇒ Boolean
Check if this is a NORMAL format SZDD file.
-
#qbasic_format? ⇒ Boolean
Check if this is a QBASIC format SZDD file.
-
#suggested_filename(compressed_filename) ⇒ String
Generate suggested output filename from compressed filename.
Constructor Details
#initialize(format: FORMAT_NORMAL, length: 0, missing_char: nil, filename: nil) ⇒ SZDDHeader
Initialize a new SZDD header
37 38 39 40 41 42 43 |
# File 'lib/cabriolet/models/szdd_header.rb', line 37 def initialize(format: FORMAT_NORMAL, length: 0, missing_char: nil, filename: nil) @format = format @length = length @missing_char = missing_char @filename = filename end |
Instance Attribute Details
#filename ⇒ String?
Original or suggested filename
29 30 31 |
# File 'lib/cabriolet/models/szdd_header.rb', line 29 def filename @filename end |
#format ⇒ Symbol
Format of the SZDD file (:normal or :qbasic)
16 17 18 |
# File 'lib/cabriolet/models/szdd_header.rb', line 16 def format @format end |
#length ⇒ Integer
Uncompressed file size in bytes
20 21 22 |
# File 'lib/cabriolet/models/szdd_header.rb', line 20 def length @length end |
#missing_char ⇒ String?
Missing character from the original filename (NORMAL format only) Commonly the last character (e.g., ‘t’ in ‘file.txt’ -> ‘file.tx_’)
25 26 27 |
# File 'lib/cabriolet/models/szdd_header.rb', line 25 def missing_char @missing_char end |
Instance Method Details
#normal_format? ⇒ Boolean
Check if this is a NORMAL format SZDD file
48 49 50 |
# File 'lib/cabriolet/models/szdd_header.rb', line 48 def normal_format? @format == FORMAT_NORMAL end |
#qbasic_format? ⇒ Boolean
Check if this is a QBASIC format SZDD file
55 56 57 |
# File 'lib/cabriolet/models/szdd_header.rb', line 55 def qbasic_format? @format == FORMAT_QBASIC end |
#suggested_filename(compressed_filename) ⇒ String
Generate suggested output filename from compressed filename
63 64 65 66 67 68 69 |
# File 'lib/cabriolet/models/szdd_header.rb', line 63 def suggested_filename(compressed_filename) return compressed_filename unless normal_format? && @missing_char # Replace trailing underscore with missing character # Pattern: ends with .XX_ where XX is any 2+ characters compressed_filename.sub(/\.(\w+)_$/, ".\\1#{@missing_char}") end |