comicbook 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a990cb3f4650a5a8efb0de5f872f7242c6a3e9f7028f137022d003f92f401f4b
4
+ data.tar.gz: b10b662cfd46bbe3126b4c834b2e5c057a227d18bed5d0a97d4bc899af843192
5
+ SHA512:
6
+ metadata.gz: 4d7e88350b4c8f9c111d68579509bdc90f8dbee09abf326a5255b9f2c4065255c1d6d863ff57df3cb42279565aee09ed67873bce779f3d734537b57c03745330
7
+ data.tar.gz: '0059293bd6b56943810b2fd5bb7ed730dfc1ad214371a5467e2ab73cd7fd8604b4ca66b822ca74051beb10187c15d193d589f58b6bfa02e7ed0d64d81cb3571c'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.7
data/AGENT.md ADDED
@@ -0,0 +1,110 @@
1
+ # AGENT.md - Development Rules
2
+
3
+ ## Core Principles
4
+
5
+ - **Be terse, not verbose in responses** - Say as little as possible
6
+ - **One small move at a time** - No large changes
7
+ - **Always write tests first** - RSpec required
8
+ - **Easy to read code** - Clarity over cleverness
9
+ - **Follow existing patterns** - No new approaches
10
+
11
+ ## Architecture Rules
12
+
13
+ ### Adapter Pattern
14
+ ```
15
+ Format (e.g., CBR)
16
+ ├── cbr.rb - inherits from Adapter
17
+ ├── archiver.rb - creates archives
18
+ └── extractor.rb - extracts archives
19
+ ```
20
+
21
+ ### TmpDir Testing
22
+ - All file I/O uses `Dir.mktmpdir`
23
+ - Never create files in repo root
24
+ - Clean up in `after` blocks
25
+
26
+ ### Output Paths
27
+ - Use `determine_output_path` method
28
+ - Place files in source directory (temp)
29
+ - Never use current working directory
30
+
31
+ ## Workflow Rules
32
+
33
+ ### Before Coding
34
+ - Read existing code first
35
+ - Use `grep`/`find_path` to understand patterns
36
+ - Don't guess - investigate
37
+
38
+ ### Development
39
+ - **Never commit without confirmation**
40
+ - Run tests - must pass
41
+ - Run RuboCop - must pass
42
+ - Provide one-line commit message
43
+
44
+ ### Testing Requirements
45
+ - Match existing coverage
46
+ - Use `load_fixture().copy_to()` pattern for all test data
47
+ - Use RSpec matchers over raw Ruby (e.g., `expect(file).to exist` not `File.exist?`)
48
+ - Include: basic, edge cases, options, errors
49
+ - Follow existing spec structure exactly
50
+
51
+ ## Quality Gates
52
+
53
+ ### Definition of Done
54
+ - [ ] All existing tests pass
55
+ - [ ] New tests pass
56
+ - [ ] RuboCop clean
57
+ - [ ] No repo root pollution
58
+ - [ ] Documentation updated
59
+ - [ ] Approved for commit
60
+
61
+ ### Test Structure
62
+ ```ruby
63
+ describe 'Component' do
64
+ let(:temp_dir) { Dir.mktmpdir }
65
+ after { FileUtils.rm_rf temp_dir }
66
+
67
+ before do
68
+ load_fixture('format/simple.ext').copy_to(test_file)
69
+ end
70
+
71
+ it 'uses RSpec matchers' do
72
+ expect(File).to exist output_path
73
+ expect(pages).to be_an Array
74
+ expect(pages).to be_all ComicBook::Page
75
+ end
76
+ end
77
+ ```
78
+
79
+ ## Adding New Formats
80
+
81
+ 1. Create fixtures (same structure as others)
82
+ 2. Main adapter (inherit from Adapter)
83
+ 3. Extractor class
84
+ 4. Archiver class (if possible)
85
+ 5. Tests matching existing patterns
86
+ 6. Update main ComicBook class detection
87
+ 7. Update documentation
88
+
89
+ ## Vendored Tools
90
+
91
+ - Use `lib/comic_book/vendor/platform/tool`
92
+ - Detect platform: macos/linux/windows
93
+ - Handle command errors gracefully
94
+ - Parse output appropriately
95
+
96
+ ## Anti-Patterns
97
+
98
+ - Files in repo root
99
+ - Breaking existing interfaces
100
+ - New patterns when existing ones work
101
+ - Skipping quality gates
102
+ - Verbose communication
103
+
104
+ ## Success Criteria
105
+
106
+ - All tests pass
107
+ - RuboCop clean
108
+ - Same patterns as CB7/CBT/CBZ
109
+ - No repo pollution
110
+ - Documentation current
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-10-26
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ veganstraightedge@gmail.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Shane Becker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # ComicBook
2
+
3
+ ⚠️ Under construction. ⚠️
4
+ A Ruby library and CLI tool for managing comic books archives.
5
+
6
+ **`extract`** — to open a `.cb*` file.
7
+
8
+ **`archive`** — to create a `.cb*` file (default: `.cbz`).
9
+
10
+ Currently supported formats, `archive` and `extract`:
11
+ - CB7 — [7zip](https://en.wikipedia.org/wiki/7-Zip)
12
+ - CBT — [Tar](https://en.wikipedia.org/wiki/Tar_(computing))
13
+ - CBZ — [Zip](https://en.wikipedia.org/wiki/ZIP_(file_format))
14
+
15
+ Planned formats , only `extract`:
16
+
17
+ - **CBR** — [RAR](https://en.wikipedia.org/wiki/WinRAR) is proprietary without an open source implementation license. People use WinRAR (Windows-only) to create .rar files. Or `unrar` on Linux/macOS to open .rar files. Extracting support is provided because a large number of comic books are archived in .cbr/.rar format, primarily by Windows users. No support for creating `.cbr` files will ever be added until RAR is opensource (or reverse engineered).
18
+ - **CBA** — [ACE](https://en.wikipedia.org/wiki/WinAce) is both proprietary and very old/outdated/unsupported. ACE extracting support is provided for historical posterity and completeness.
19
+
20
+ ## Installation
21
+
22
+ Install the gem and add to the application's Gemfile by executing:
23
+
24
+ ```sh
25
+ bundle add comicbook
26
+ ```
27
+
28
+ If bundler is not being used to manage dependencies, install the gem by executing:
29
+
30
+ ```sh
31
+ gem install comicbook
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ In Ruby, you can use the `ComicBook` class to `extract` comic books archives from various formats. You `archive` a folder of images to create a comic book archive.
37
+
38
+ ### Extracting
39
+
40
+ ```ruby
41
+ ComicBook.extract 'path/to/archive.cbz'
42
+ ```
43
+ ### Archiving
44
+
45
+ ```ruby
46
+ ComicBook.archive 'path/to/archive'
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/veganstraightedge/comicbook. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/veganstraightedge/comicbook/blob/main/CODE_OF_CONDUCT.md).
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
62
+
63
+ ## Code of Conduct
64
+
65
+ Everyone interacting in the Comicbook project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/veganstraightedge/comicbook/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new :spec
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: %i[spec rubocop]
data/SYSTEM.md ADDED
@@ -0,0 +1,235 @@
1
+ # ComicBook Ruby - System Documentation
2
+
3
+ ## Overview
4
+
5
+ ComicBook Ruby is a Ruby library for reading, writing, and manipulating comic book archive files. It provides a unified interface for working with multiple comic book formats including CBZ (ZIP), CB7 (7-Zip), CBT (TAR), CBR (RAR), and CBA (ACE) archives.
6
+
7
+ ## Project Structure
8
+
9
+ ```
10
+ comicbook-ruby/
11
+ ├── lib/
12
+ │ ├── comicbook.rb # Main entry point and public API
13
+ │ └── comic_book/
14
+ │ ├── adapter.rb # Base adapter class
15
+ │ ├── page.rb # Page representation
16
+ │ ├── version.rb # Version constant
17
+ │ ├── cli_helpers.rb # CLI utility functions
18
+ │ ├── cb7.rb # CB7 (7-Zip) adapter
19
+ │ ├── cb7/
20
+ │ │ ├── archiver.rb # CB7 archive creation
21
+ │ │ └── extractor.rb # CB7 archive extraction
22
+ │ ├── cbt.rb # CBT (TAR) adapter
23
+ │ ├── cbt/
24
+ │ │ ├── archiver.rb # CBT archive creation
25
+ │ │ └── extractor.rb # CBT archive extraction
26
+ │ ├── cbz.rb # CBZ (ZIP) adapter
27
+ │ ├── cbz/
28
+ │ │ ├── archiver.rb # CBZ archive creation
29
+ │ │ └── extractor.rb # CBZ archive extraction
30
+ │ └── vendor/ # Vendored dependencies
31
+ ├── spec/ # RSpec test suite
32
+ │ ├── fixtures/ # Test fixtures for all formats
33
+ │ └── comic_book/ # Organized test files
34
+ └── bin/ # Executables and development tools
35
+ ```
36
+
37
+ ## Architecture
38
+
39
+ ### Core Design Patterns
40
+
41
+ #### 1. Adapter Pattern
42
+ The system uses the Adapter pattern to provide a unified interface across different comic book archive formats. Each format (CBZ, CB7, CBT, etc.) implements the same interface defined by `ComicBook::Adapter`.
43
+
44
+ ```ruby
45
+ class ComicBook::Adapter
46
+ def archive(options = {}) # Create archive from folder (to: destination_path)
47
+ def extract(options = {}) # Extract archive to folder (to: destination_path)
48
+ def pages # Get array of Page objects
49
+ end
50
+ ```
51
+
52
+ #### 2. Strategy Pattern
53
+ The main `ComicBook` class acts as a context that delegates to the appropriate adapter based on file type detection:
54
+
55
+ ```ruby
56
+ def adapter
57
+ case type
58
+ when :cb7 then CB7.new path
59
+ when :cbt then CBT.new path
60
+ when :cbz then CBZ.new path
61
+ # ... other formats
62
+ end
63
+ end
64
+ ```
65
+
66
+ #### 3. Template Method Pattern
67
+ Each adapter family (CB7, CBT, CBZ) follows a consistent structure with separate Archiver and Extractor classes that implement format-specific operations while sharing common patterns.
68
+
69
+ ### Key Components
70
+
71
+ #### 1. ComicBook (Main Class)
72
+ - **Location**: `lib/comicbook.rb`
73
+ - **Purpose**: Public API entry point and file type detection
74
+ - **Responsibilities**:
75
+ - File type detection based on extensions
76
+ - Path validation
77
+ - Delegation to appropriate adapters
78
+ - Unified interface for all operations
79
+
80
+ #### 2. ComicBook::Adapter (Base Class)
81
+ - **Location**: `lib/comic_book/adapter.rb`
82
+ - **Purpose**: Abstract base class for all format adapters
83
+ - **Pattern**: Template method defining common interface
84
+ - **Key Methods**: `archive`, `extract`, `pages`
85
+
86
+ #### 3. Format Adapters
87
+ Each format has three components:
88
+
89
+ **Main Adapter** (`cb7.rb`, `cbt.rb`, `cbz.rb`)
90
+ - Inherits from `ComicBook::Adapter`
91
+ - Delegates to Archiver/Extractor classes
92
+ - Implements `pages` method for reading archive contents
93
+
94
+ **Archiver Classes** (`*/archiver.rb`)
95
+ - Handles creation of archives from source folders
96
+ - Implements format-specific compression
97
+ - Manages file filtering (images only)
98
+ - Supports options like custom extensions and delete_original
99
+
100
+ **Extractor Classes** (`*/extractor.rb`)
101
+ - Handles extraction of archives to folders
102
+ - Implements format-specific decompression
103
+ - Filters extracted files (images only)
104
+ - Supports custom destinations and extensions
105
+
106
+ #### 4. ComicBook::Page
107
+ - **Location**: `lib/comic_book/page.rb`
108
+ - **Purpose**: Represents a single page/image within a comic archive
109
+ - **Attributes**: `path` (file path), `name` (display name)
110
+
111
+ ### File Type Support
112
+
113
+ | Format | Extension | Status | Compression | Dependencies |
114
+ |--------|-----------|--------|-------------|--------------|
115
+ | CBZ | `.cbz` | ✅ Full | ZIP | `rubyzip` gem |
116
+ | CB7 | `.cb7` | ✅ Full | 7-Zip | `seven-zip` gem |
117
+ | CBT | `.cbt` | ✅ Full | TAR | Ruby stdlib |
118
+ | CBR | `.cbr` | 🚧 Planned | RAR | TBD |
119
+ | CBA | `.cba` | 🚧 Planned | ACE | TBD |
120
+
121
+ ### Data Flow
122
+
123
+ #### Archive Creation Flow
124
+ 1. User calls `ComicBook.new(folder_path).archive()`
125
+ 2. Main class detects folder type
126
+ 3. Delegates to CBZ adapter (default for folders)
127
+ 4. CBZ creates Archiver instance
128
+ 5. Archiver scans folder for image files
129
+ 6. Creates ZIP archive with filtered content
130
+ 7. Returns path to created archive
131
+
132
+ #### Archive Extraction Flow
133
+ 1. User calls `ComicBook.new(archive_path).extract()`
134
+ 2. Main class detects file type by extension
135
+ 3. Delegates to appropriate adapter (CB7, CBT, CBZ)
136
+ 4. Adapter creates Extractor instance
137
+ 5. Extractor reads archive contents
138
+ 6. Filters for image files only
139
+ 7. Extracts to destination folder
140
+ 8. Returns path to extracted folder
141
+
142
+ #### Page Reading Flow
143
+ 1. User calls `ComicBook.new(archive_path).pages`
144
+ 2. Main class delegates to appropriate adapter
145
+ 3. Adapter reads archive contents
146
+ 4. Filters for image files
147
+ 5. Creates Page objects with path and name
148
+ 6. Returns sorted array of Page objects
149
+
150
+ ## Configuration & Constants
151
+
152
+ ### Image File Support
153
+ ```ruby
154
+ IMAGE_EXTENSIONS = %w[.jpg .jpeg .png .gif .bmp .webp].freeze
155
+ IMAGE_GLOB_PATTERN = '*.{jpg,jpeg,png,gif,bmp,webp}'.freeze
156
+ ```
157
+
158
+ The system automatically filters files to include only recognized image formats when creating or extracting archives.
159
+
160
+ ### Options Support
161
+ All archive and extract operations support these options:
162
+ - `extension`: Custom file extension for output
163
+ - `delete_original`: Boolean to remove source after operation
164
+ - `destination`: Custom output path
165
+
166
+ ## Dependencies
167
+
168
+ ### Runtime Dependencies
169
+ - **rubyzip** (>= 3.2.1): ZIP file handling for CBZ format
170
+ - **seven-zip** (~> 1.4): 7-Zip handling for CB7 format
171
+ - Ruby stdlib: TAR handling for CBT format
172
+
173
+ ### Development Dependencies
174
+ - **rspec**: Testing framework
175
+ - **rspec-file_fixtures**: Fixture management for tests
176
+ - **rubocop**: Code linting and style enforcement
177
+
178
+ ## Testing Strategy
179
+
180
+ ### Test Organization
181
+ - **Unit Tests**: Individual component testing
182
+ - **Integration Tests**: End-to-end format operations
183
+ - **Fixture-Based**: Real archive files for accurate testing
184
+
185
+ ### TmpDir Pattern
186
+ All tests use `Dir.mktmpdir` for file I/O operations to ensure:
187
+ - No files created in repository root
188
+ - Proper cleanup after each test
189
+ - Isolation between test runs
190
+
191
+ ### Test Coverage
192
+ - 173 examples across all components
193
+ - Full coverage of archive/extract/pages operations
194
+ - Edge cases: empty archives, non-image files, nested folders
195
+
196
+ ## Performance Considerations
197
+
198
+ ### Memory Usage
199
+ - Streaming operations where possible
200
+ - No full file loading into memory for large archives
201
+ - Lazy page enumeration
202
+
203
+ ### File I/O
204
+ - Temporary directory usage prevents repository pollution
205
+ - Atomic operations with proper cleanup
206
+ - Path normalization for cross-platform compatibility
207
+
208
+ ## Error Handling
209
+
210
+ ### Exception Hierarchy
211
+ ```ruby
212
+ ComicBook::Error < StandardError
213
+ ```
214
+
215
+ ### Common Error Cases
216
+ - Unsupported file types
217
+ - Missing dependencies for format handlers
218
+ - Invalid or corrupted archive files
219
+ - Permission issues during file operations
220
+
221
+ ## Future Extensibility
222
+
223
+ ### Adding New Formats
224
+ 1. Create new adapter class inheriting from `ComicBook::Adapter`
225
+ 2. Implement archiver and extractor classes
226
+ 3. Add format detection to main `ComicBook` class
227
+ 4. Add comprehensive test suite following existing patterns
228
+
229
+ ### Plugin Architecture
230
+ The adapter pattern makes it easy to add new formats or extend existing ones without modifying core functionality.
231
+
232
+ ## Version Information
233
+ - **Current Version**: 0.1.0
234
+ - **Ruby Requirement**: >= 3.4.7
235
+ - **License**: MIT
data/exe/comicbook ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/comicbook'
4
+ require_relative '../lib/comic_book/cli'
5
+
6
+ ComicBook::CLI.start ARGV
@@ -0,0 +1,26 @@
1
+ # NOTE: don't use ComicBook::Adapter.new directly
2
+ # Inherit from it when making an adapter to formats:
3
+ # .cb7 .cba .cbr .cbt .cbz
4
+ class ComicBook
5
+ class Adapter
6
+ def initialize path
7
+ @path = File.expand_path path
8
+ end
9
+
10
+ def archive options = {}
11
+ raise NotImplementedError, "#{self.class} must implement #archive"
12
+ end
13
+
14
+ def extract options = {}
15
+ raise NotImplementedError, "#{self.class} must implement #extract"
16
+ end
17
+
18
+ def pages
19
+ raise NotImplementedError, "#{self.class} must implement #pages"
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :path
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ class ComicBook
2
+ class CB7 < Adapter
3
+ class Archiver
4
+ def initialize source_folder
5
+ @source_folder = File.expand_path source_folder
6
+ end
7
+
8
+ def archive options = {}
9
+ extension = options.fetch :extension, :cb7
10
+ delete_original = options.fetch :delete_original, false
11
+
12
+ output_path = options[:to] || determine_output_path(extension)
13
+ create_7z_archive output_path
14
+ cleanup_source_folder if delete_original
15
+
16
+ output_path
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :source_folder
22
+
23
+ def determine_output_path extension
24
+ base_name = File.basename source_folder, '.*'
25
+ dir_name = File.dirname source_folder
26
+
27
+ File.expand_path File.join(dir_name, "#{base_name}.#{extension}")
28
+ end
29
+
30
+ def create_7z_archive output_path
31
+ File.open(output_path, 'wb') do |file|
32
+ SevenZipRuby::Writer.open(file) do |szw|
33
+ find_image_files.each do |image_file|
34
+ add_file_to_7z szw, image_file
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def find_image_files
41
+ pattern = File.join(source_folder, '**', ComicBook::IMAGE_GLOB_PATTERN)
42
+ Dir.glob(pattern, File::FNM_CASEFOLD).sort
43
+ end
44
+
45
+ def add_file_to_7z szw, file
46
+ file_path = Pathname.new file
47
+ source_path = Pathname.new source_folder
48
+ relative_path = file_path.relative_path_from source_path
49
+
50
+ szw.add_file file, as: relative_path.to_s
51
+ end
52
+
53
+ def cleanup_source_folder
54
+ FileUtils.rm_rf source_folder
55
+ end
56
+ end
57
+ end
58
+ end