comicbook 0.3.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e9032e12765aa91a64364150391122a0324ee9f89b9987391f4708d1db7b0d6
4
- data.tar.gz: de1dc67b4d78eb8ecf739b02381d78cf2a39518a6b12dd6bbef521dd77e1b8dd
3
+ metadata.gz: 031eb52d98db1f37e3b6591962bdf59b1eeded272880d535c54498a43aaccac5
4
+ data.tar.gz: e28d1becaa131307edefc55f9c08809fed7e2eea1db6caa985f728230564fc1e
5
5
  SHA512:
6
- metadata.gz: 81a45ca97a476926a1d8216043069840e27f42c461175ebf0326cd0698e4cc0ea78f8627b3b932e23266ccc56081786eaec210cbbc07d1e5e452b11bcef94f4e
7
- data.tar.gz: f073563d4dcc6253d140e6818f2c9e273dfdc8e6ce053a729b6cddddb115ef436d6afa80d3e4357cf2ff187112bb69f444032674a5a96db841a7df0664ff0f7e
6
+ metadata.gz: ef8be7943dae6f665343d7e9ec890fbecf062e549a091fc4c77ed0959380a6a59eb6896fe08b18e2380cc2d49c282654dae4a3f089032554617ee820305eba86
7
+ data.tar.gz: 299be6b9328f8729140a1509716c63addbdcd36ee47cb01535c05aeaf61e2bc0a55e8f3e2aa3b9ddd13e6d6073a6b33bf9963a04b04faf210b0cb0e66dcac2f1
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 4.0.2
1
+ 4.0.9
data/AGENT.md CHANGED
@@ -12,10 +12,10 @@
12
12
 
13
13
  ### Adapter Pattern
14
14
  ```
15
- Format (e.g., CBR)
16
- ├── cbr.rb - inherits from Adapter
17
- ├── archiver.rb - creates archives
18
- └── extractor.rb - extracts archives
15
+ Format (e.g., CBZ)
16
+ ├── cbz.rb - inherits from Adapter
17
+ ├── cbz/archiver.rb - creates archives (not for extract-only formats: CBR, PDF)
18
+ └── cbz/extractor.rb - extracts archives
19
19
  ```
20
20
 
21
21
  ### TmpDir Testing
@@ -88,8 +88,9 @@ end
88
88
 
89
89
  ## Vendored Tools
90
90
 
91
- - Use `lib/comic_book/vendor/platform/tool`
92
- - Detect platform: macos/linux/windows
91
+ - `lsar` / `unar` (for CBR) live in `lib/comic_book/vendor/<platform>/` for macos and windows
92
+ - On linux they are not vendored: `ComicBook::CLIHelpers` expects them installed on the system
93
+ - Run them through `ComicBook::CLIHelpers`, which detects the platform
93
94
  - Handle command errors gracefully
94
95
  - Parse output appropriately
95
96
 
@@ -105,6 +106,6 @@ end
105
106
 
106
107
  - All tests pass
107
108
  - RuboCop clean
108
- - Same patterns as CB7/CBT/CBZ
109
+ - Same patterns as CB7/CBR/CBT/CBZ
109
110
  - No repo pollution
110
111
  - Documentation current
data/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2026-11-19
4
+
5
+ ### Added
6
+
7
+ - `ComicBook#arrange_pages(sources, template:)`: make a folder's page images exactly the given files, in order. Reorders, deletes, and adds pages of an extracted comic in one step: pages stay in the subfolder they were in, files that are not images are left alone, and a `ComicInfo.xml` in the folder has its `<Page>` entries and `PageCount` updated to match. Pages are named `page_001…` unless a `template:` such as `{series}_{number:3}_{page:4}` is given, which the comicinfo gem's `Issue#page_filename` fills in from the folder's `ComicInfo.xml`. `ComicBook::PageArranger` does the work
8
+ - Format support is public: `ComicBook::TYPES`, `ComicBook::READABLE_TYPES` (everything but `:cba`) and `ComicBook::WRITABLE_TYPES` (`:cb`, `:cb7`, `:cbt`, `:cbz`)
9
+ - `ComicBook::DEFAULT_PAGE_FILENAME_TEMPLATE` (`page_{page:3}`)
10
+
11
+ ### Fixed
12
+
13
+ - Mislabelled archives now open. A comic's type is told from the bytes the file starts with, so a RAR named `.cbz` (common in the wild) loads with `type == :cbr` and is read as one. ZIP, RAR, 7-Zip, TAR, PDF and ACE are recognized, by the new `ComicBook::Signature`. The extension still decides which files are comics at all (a `.zip` is refused as before) and is used when the contents are not recognized
14
+ - macOS metadata is no longer part of a comic. Archives made on a Mac can carry AppleDouble members (`._page1.jpg`, written by `tar` beside a file with extended attributes) or a `__MACOSX` folder (where Finder's Compress puts the same data). They were listed as files, counted as pages because their names end in an image extension, and extracted. All formats now leave them out of `files`, `pages` and `extract`, and a folder's `__MACOSX` is left out when it is archived. `ComicBook::Entry#macos_metadata?` is the check
15
+
16
+ ### Changed
17
+
18
+ - Requires comicinfo 2.1 or later (was 2.0)
19
+ - CI runs on `ubuntu-24.04` instead of `ubuntu-latest`: on Ubuntu 26.04 the `seven-zip` gem crashed Ruby when reading an empty 7z
20
+ - CI retries a stalled package download instead of hanging, and installs from Ubuntu's main archive: installing `unar` and `libvips-dev` was stalling on the runner's regional mirror
21
+ - Bump Ruby version from 4.0.5 to 4.0.9 (`.ruby-version`, `required_ruby_version`, CI matrix)
22
+ - Brought `README.md`, `SYSTEM.md`, `AGENT.md` and `TODO.md` up to date: CBR, PDF, `.cb` folders, the CLI, `files`, and `contents:` are documented as they work today; finished roadmap items are removed
23
+
24
+ ## [0.4.0] - 2026-06-18
25
+
26
+ ### Added
27
+
28
+ - `contents:` option when archiving a folder — choose what goes into the archive: `:all` (default, every file), `:images` (images only), or `:images_and_info` (images plus `ComicInfo.xml` / `MetronInfo.xml`). Lets a comic be repackaged without dropping its metadata sidecars
29
+ - `ComicBook#files(type:)` — list a comic's files, filtered the same three ways, as `ComicBook::Entry` objects that answer `#image?` and `#info?`
30
+
31
+ ### Changed
32
+
33
+ - Pages are now ordered by full entry path; archives previously ordered by basename (affects nested archives only)
34
+ - Bump Ruby version from 4.0.2 to 4.0.5 (`.ruby-version`, `required_ruby_version`, CI matrix)
35
+
3
36
  ## [0.3.0] - 2026-04-14
4
37
 
5
38
  ### Added
data/README.md CHANGED
@@ -1,25 +1,40 @@
1
1
  # ComicBook
2
2
 
3
- ⚠️ Under construction. ⚠️
4
3
  A Ruby library and CLI tool for managing comic books archives.
5
4
 
6
- **`extract`** — to open a `.cb*` file.
5
+ - `extract`: to open a `.cb*` file
6
+ - `archive`: to create a `.cb*` file
7
+ - `info`: to read `ComicInfo.xml` metadata from a `.cb*` file
8
+ - `pages`: to list page image files in a `.cb*` file (Ruby API only)
9
+ - `arrange_pages`: to reorder, delete, and add pages of an extracted comic (Ruby API only)
7
10
 
8
- **`archive`** — to create a `.cb*` file (default: `.cbz`).
11
+ ---
9
12
 
10
- **`info`** — to read ComicInfo.xml metadata from a `.cb*` file.
13
+ Support for `archive` and `extract` :
11
14
 
12
- Currently supported formats for `archive` and `extract`:
13
- - CB7 — [7zip](https://en.wikipedia.org/wiki/7-Zip)
14
- - CBT — [Tar](https://en.wikipedia.org/wiki/Tar_(computing))
15
- - CBZ — [Zip](https://en.wikipedia.org/wiki/ZIP_(file_format))
15
+ - `CB`: a folder of images, an optional `ComicInfo.xml` metadata file
16
+ - `CB7`: [7zip](https://en.wikipedia.org/wiki/7-Zip)
17
+ - `CBT`: [Tar](<https://en.wikipedia.org/wiki/Tar_(computing)>)
18
+ - `CBZ`: [Zip](<https://en.wikipedia.org/wiki/ZIP_(file_format)>) **default**
16
19
 
17
- Currently supported formats for `extract` only:
18
- - **CBR** — [RAR](https://en.wikipedia.org/wiki/WinRAR) is proprietary without an open source implementation license. Extracting support is provided using vendored [`unar`](https://theunarchiver.com/command-line) binaries because a large number of comic books are archived in .cbr/.rar format. No support for creating `.cbr` files will ever be added until RAR is open source (or reverse engineered).
19
- - **PDF** — Extract PDF pages as images using [libvips](https://www.libvips.org/). Requires libvips installed on the system.
20
+ Support for only `extract`:
20
21
 
21
- Planned formats for `extract` only:
22
- - **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.
22
+ - `CBR`: [RAR](https://en.wikipedia.org/wiki/WinRAR) is proprietary without an open source implementation license.
23
+ Uses the `lsar` / `unar` tools: bundled for macOS and Windows, on Linux install the `unar` package.
24
+ Extracting support because a large number of comic books are archived in .cbr/.rar format.
25
+ No support for creating `.cbr` files will ever be added unless `RAR` is open source (or reverse engineered).
26
+ - `PDF`: Convert a PDF to a `.cb*` archive using [libvips](https://www.libvips.org) . Requires `libvips` installed on the system.
27
+
28
+ A comic's type comes from what the file contains, not its name, so a mislabelled archive still opens: a RAR named `.cbz` is read as a CBR.
29
+ The name still decides which files are comics at all (a `.zip` is refused).
30
+
31
+ Files that macOS adds to archives it makes (`._page1.jpg`, a `__MACOSX` folder) are never listed, counted as pages, or extracted.
32
+
33
+ Not supported yet:
34
+
35
+ - `CBA`: [ACE](https://en.wikipedia.org/wiki/WinAce) is both proprietary and very old/outdated/unsupported.
36
+ ACE extracting support is planned, to support historical posterity and completeness.
37
+ **NEEDED: actual `.cba` files** to test against (with and without `ComicInfo.xml`).
23
38
 
24
39
  ## Installation
25
40
 
@@ -52,11 +67,14 @@ comicbook extract path/to/archive.cbz --images-only
52
67
  # Extract PDF at custom DPI (default: 300)
53
68
  comicbook extract path/to/comic.pdf --dpi 600
54
69
 
70
+ # Delete the source after extracting (or archiving)
71
+ comicbook extract path/to/archive.cbz --delete-original
72
+
55
73
  # Create a comic book archive from a folder
56
74
  comicbook archive path/to/folder
57
75
 
58
- # Create archive at a specific destination
59
- comicbook archive path/to/folder --to path/to/output.cbz
76
+ # Create archive at a specific destination (the extension picks the format: .cbz, .cb7, .cbt, .cb)
77
+ comicbook archive path/to/folder --to path/to/output.cb7
60
78
 
61
79
  # Show ComicInfo.xml metadata
62
80
  comicbook info path/to/archive.cbz
@@ -65,6 +83,7 @@ comicbook info path/to/archive.cbz
65
83
  comicbook info path/to/archive.cbz --format json
66
84
  comicbook info path/to/archive.cbz --format yaml
67
85
  comicbook info path/to/archive.cbz --format terse
86
+ comicbook info path/to/archive.cbz --format verbose # default
68
87
 
69
88
  # Show only specific fields
70
89
  comicbook info path/to/archive.cbz --only title,writer,publisher
@@ -72,8 +91,9 @@ comicbook info path/to/archive.cbz --only title,writer,publisher
72
91
  # Show all fields except specific ones
73
92
  comicbook info path/to/archive.cbz --except summary,review
74
93
 
75
- # Show help
94
+ # Show help or version
76
95
  comicbook --help
96
+ comicbook --version
77
97
  ```
78
98
 
79
99
  ### Ruby API
@@ -91,13 +111,36 @@ ComicBook.extract 'path/to/archive.cbz', images_only: true
91
111
  # Create a comic book archive from a folder (creates .cbz by default)
92
112
  ComicBook.new('path/to/folder').archive
93
113
 
94
- # Create archive at a specific destination
114
+ # Create archive at a specific destination (the extension picks the format)
95
115
  ComicBook.new('path/to/folder').archive to: 'path/to/output.cbz'
96
116
 
117
+ # Choose what goes into the archive: :all (default), :images, or :images_and_info
118
+ ComicBook.new('path/to/folder').archive contents: :images_and_info
119
+
97
120
  # Get pages from an archive
98
121
  comic = ComicBook.new 'path/to/archive.cbz'
99
122
  comic.pages # => [#<ComicBook::Page>, ...]
100
123
 
124
+ # List files in an archive: :all (default), :images, or :images_and_info
125
+ comic.files # => [#<ComicBook::Entry>, ...]
126
+ comic.files type: :images # => [#<ComicBook::Entry>, ...]
127
+
128
+ # Reorder, delete, and add pages of an extracted comic, then archive it again.
129
+ # Each source is a page already in the folder (relative path) or any image file (absolute path).
130
+ extracted = ComicBook.new 'path/to/extracted.cb'
131
+ extracted.arrange_pages ['page3.jpg', 'page1.jpg', '/Users/me/Desktop/extra.png']
132
+ extracted.archive to: 'path/to/output.cbz'
133
+
134
+ # Pages are renumbered page_001... in the given order, page images left out are deleted,
135
+ # and a ComicInfo.xml in the folder has its <Page> entries and PageCount updated to match.
136
+ # Pass a template to name the page files another way. It can use {page} and the comic's
137
+ # details, and the names always sort in page order. Write it in single quotes.
138
+ extracted.arrange_pages sources, template: '{series}_{number:3}_{page:4}' # Saga_007_0001.jpg ...
139
+
140
+ # Which formats can be opened, and which can be written
141
+ ComicBook::READABLE_TYPES # => [:cb, :cb7, :cbr, :cbt, :cbz, :folder, :pdf]
142
+ ComicBook::WRITABLE_TYPES # => [:cb, :cb7, :cbt, :cbz]
143
+
101
144
  # Read ComicInfo.xml metadata
102
145
  comic = ComicBook.new 'path/to/archive.cbz'
103
146
  comic.info # => #<ComicInfo::Issue> or nil
@@ -114,9 +157,7 @@ brew install vips # macOS
114
157
  sudo apt install libvips-dev # Linux
115
158
  ```
116
159
 
117
- 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.
118
-
119
- 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).
160
+ 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. To install this gem onto your local machine, run `bundle exec rake install`.
120
161
 
121
162
  ## Contributing
122
163
 
data/SYSTEM.md CHANGED
@@ -2,36 +2,53 @@
2
2
 
3
3
  ## Overview
4
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.
5
+ ComicBook is a Ruby library and CLI for reading, writing, and converting comic book archive files. It provides one interface over several formats: CB (folder), CBZ (ZIP), CB7 (7-Zip), CBT (TAR), CBR (RAR, extract only), and PDF (extract only). CBA (ACE) is recognised but not implemented.
6
6
 
7
7
  ## Project Structure
8
8
 
9
9
  ```
10
- comicbook-ruby/
10
+ comicbook/
11
+ ├── exe/
12
+ │ └── comicbook # CLI executable
11
13
  ├── lib/
12
- │ ├── comicbook.rb # Main entry point and public API
14
+ │ ├── comicbook.rb # Main entry point and public API
13
15
  │ └── 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
16
+ │ ├── adapter.rb # Base adapter class
17
+ │ ├── cli.rb # CLI commands (extract, archive, info)
18
+ │ ├── cli_helpers.rb # Runs the lsar / unar tools
19
+ │ ├── entry.rb # One file inside a comic
20
+ │ ├── page.rb # Page representation
21
+ │ ├── page_arranger.rb # Reorders, deletes and adds a folder's pages
22
+ │ ├── signature.rb # A file's type, from the bytes it starts with
23
+ │ ├── version.rb # Version constant
24
+ │ ├── cb.rb # CB (folder) adapter
25
+ │ ├── cb/
26
+ │ │ ├── archiver.rb
27
+ │ │ └── extractor.rb # Always raises: a .cb folder is already extracted
18
28
  │ ├── cb7.rb # CB7 (7-Zip) adapter
19
29
  │ ├── cb7/
20
- │ │ ├── archiver.rb # CB7 archive creation
21
- │ │ └── extractor.rb # CB7 archive extraction
30
+ │ │ ├── archiver.rb
31
+ │ │ └── extractor.rb
32
+ │ ├── cba.rb # CBA (ACE) stub: every operation raises
33
+ │ ├── cbr.rb # CBR (RAR) adapter
34
+ │ ├── cbr/
35
+ │ │ └── extractor.rb
22
36
  │ ├── cbt.rb # CBT (TAR) adapter
23
37
  │ ├── cbt/
24
- │ │ ├── archiver.rb # CBT archive creation
25
- │ │ └── extractor.rb # CBT archive extraction
38
+ │ │ ├── archiver.rb
39
+ │ │ └── extractor.rb
26
40
  │ ├── cbz.rb # CBZ (ZIP) adapter
27
41
  │ ├── cbz/
28
- │ │ ├── archiver.rb # CBZ archive creation
29
- │ │ └── extractor.rb # CBZ archive extraction
30
- │ └── vendor/ # Vendored dependencies
42
+ │ │ ├── archiver.rb
43
+ │ │ └── extractor.rb
44
+ │ ├── pdf.rb # PDF adapter
45
+ │ ├── pdf/
46
+ │ │ └── extractor.rb # Renders each PDF page to an image
47
+ │ └── vendor/ # lsar / unar binaries (macOS, Windows)
31
48
  ├── spec/ # RSpec test suite
32
49
  │ ├── fixtures/ # Test fixtures for all formats
33
- │ └── comic_book/ # Organized test files
34
- └── bin/ # Executables and development tools
50
+ │ └── comic_book/ # One spec per component
51
+ └── bin/ # Development tools (setup, console)
35
52
  ```
36
53
 
37
54
  ## Architecture
@@ -39,32 +56,39 @@ comicbook-ruby/
39
56
  ### Core Design Patterns
40
57
 
41
58
  #### 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`.
59
+ Each format implements the interface defined by `ComicBook::Adapter`.
43
60
 
44
61
  ```ruby
45
62
  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
63
+ def archive(options = {}) # Create archive from folder
64
+ def extract(options = {}) # Extract archive to folder
65
+ def entries # Every file in the comic, as Entry objects
66
+ def info # ComicInfo::Issue from ComicInfo.xml, or nil
67
+ def pages # Page objects (only PDF and CBA define this themselves)
68
+ def images # entries that are images
69
+ def images_and_info # entries that are images or info files
49
70
  end
50
71
  ```
51
72
 
52
73
  #### 2. Strategy Pattern
53
- The main `ComicBook` class acts as a context that delegates to the appropriate adapter based on file type detection:
74
+ The main `ComicBook` class picks the adapter from the detected type:
54
75
 
55
76
  ```ruby
56
77
  def adapter
57
78
  case type
58
79
  when :cb7 then CB7.new path
80
+ when :cba then CBA.new path
81
+ when :cbr then CBR.new path
59
82
  when :cbt then CBT.new path
60
83
  when :cbz then CBZ.new path
61
- # ... other formats
84
+ when :pdf then PDF.new path
85
+ when :cb, :folder then CB.new path
62
86
  end
63
87
  end
64
88
  ```
65
89
 
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.
90
+ #### 3. Archiver / Extractor Classes
91
+ Each adapter delegates to an `Archiver` and an `Extractor` class that hold the format-specific work. Formats that cannot be written (CBR, PDF) have only an `Extractor`.
68
92
 
69
93
  ### Key Components
70
94
 
@@ -72,108 +96,128 @@ Each adapter family (CB7, CBT, CBZ) follows a consistent structure with separate
72
96
  - **Location**: `lib/comicbook.rb`
73
97
  - **Purpose**: Public API entry point and file type detection
74
98
  - **Responsibilities**:
75
- - File type detection based on extensions
99
+ - Type detection: a folder is `:folder`, or `:cb` if its name ends in `.cb`; a file must have a comic extension, and is typed by its contents (`ComicBook::Signature`), falling back to the extension
76
100
  - Path validation
77
- - Delegation to appropriate adapters
78
- - Unified interface for all operations
101
+ - Delegation to the adapter
102
+ - `archive`, `extract`, `info`, `files(type:)`, `pages`, `arrange_pages(sources, template:)` (done by `ComicBook::PageArranger`)
103
+ - `ComicBook::Info` is an alias of `ComicInfo::Issue`
79
104
 
80
105
  #### 2. ComicBook::Adapter (Base Class)
81
106
  - **Location**: `lib/comic_book/adapter.rb`
82
107
  - **Purpose**: Abstract base class for all format adapters
83
- - **Pattern**: Template method defining common interface
84
- - **Key Methods**: `archive`, `extract`, `pages`
85
108
 
86
109
  #### 3. Format Adapters
87
- Each format has three components:
88
110
 
89
- **Main Adapter** (`cb7.rb`, `cbt.rb`, `cbz.rb`)
111
+ **Main Adapter** (`cb.rb`, `cb7.rb`, `cbr.rb`, `cbt.rb`, `cbz.rb`, `pdf.rb`)
90
112
  - Inherits from `ComicBook::Adapter`
91
113
  - Delegates to Archiver/Extractor classes
92
- - Implements `pages` method for reading archive contents
114
+ - Implements `entries` and `info`
93
115
 
94
116
  **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
117
+ - Create an archive from a source folder
118
+ - Choose which files go in with the `contents` option
99
119
 
100
120
  **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
121
+ - Extract an archive to a folder
122
+ - Extract every file unless `images_only` is set
105
123
 
106
- #### 4. ComicBook::Page
124
+ #### 4. ComicBook::Entry
125
+ - **Location**: `lib/comic_book/entry.rb`
126
+ - **Purpose**: One file inside a comic
127
+ - **Attributes**: `path` (relative path in a folder, or entry name in an archive), `name` (basename)
128
+ - **Predicates**: `image?`, `info?` (`ComicInfo.xml` or `MetronInfo.xml`), `macos_metadata?` (a `._` file or anything in `__MACOSX`; never listed or extracted)
129
+
130
+ #### 5. ComicBook::Page
107
131
  - **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)
132
+ - **Purpose**: One page image of a comic
133
+ - **Attributes**: `path`, `name`
134
+
135
+ #### 6. ComicBook::CLI
136
+ - **Location**: `lib/comic_book/cli.rb`, run by `exe/comicbook`
137
+ - **Commands**: `extract`, `archive`, `info`
110
138
 
111
139
  ### File Type Support
112
140
 
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 |
141
+ | Format | Extension | Archive | Extract | Info | Dependencies |
142
+ |--------|--------------|-----------------------|-----------------------------|-----------------|---------------------------|
143
+ | CB | `.cb` folder | ✅ | n/a (already a folder) | ✅ | Ruby stdlib |
144
+ | CBZ | `.cbz` | ✅ | ✅ | ✅ | `rubyzip` gem |
145
+ | CB7 | `.cb7` | ✅ | ✅ | ✅ | `seven-zip` gem |
146
+ | CBT | `.cbt` | ✅ | ✅ | ✅ | Ruby stdlib |
147
+ | CBR | `.cbr` | ❌ RAR is proprietary | ✅ | ✅ | `lsar` / `unar` |
148
+ | PDF | `.pdf` | ❌ | ✅ pages rendered to images | ❌ always `nil` | `ruby-vips` gem + libvips |
149
+ | CBA | `.cba` | ❌ ACE is proprietary | 🚧 Planned | 🚧 Planned | TBD |
150
+
151
+ `lsar` and `unar` are vendored for macOS and Windows in `lib/comic_book/vendor/`. On Linux they must be installed on the system (`unar` package).
120
152
 
121
153
  ### Data Flow
122
154
 
123
155
  #### 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
156
+ 1. User calls `ComicBook.new(folder_path).archive`
157
+ 2. Main class checks the path is a folder (or `.cb` folder)
158
+ 3. The extension of the `to:` option picks the adapter (`.cbz` by default)
159
+ 4. The adapter's Archiver lists the folder's files, filtered by `contents`
160
+ 5. Creates the archive
161
+ 6. Returns the path of the created archive
131
162
 
132
163
  #### 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
164
+ 1. User calls `ComicBook.new(archive_path).extract`
165
+ 2. Main class detects file type from the file's contents, falling back to its extension
166
+ 3. Delegates to the adapter's Extractor
167
+ 4. Extracts every file (only images if `images_only` is set) to the destination folder
168
+ 5. Returns the path of the extracted folder
169
+
170
+ For a PDF, step 4 renders each page to an image at the `dpi` option's resolution.
141
171
 
142
172
  #### Page Reading Flow
143
173
  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
174
+ 2. Main class asks the adapter for its entries
175
+ 3. Keeps the image files, sorted by path
176
+ 4. Returns an array of Page objects
149
177
 
150
178
  ## Configuration & Constants
151
179
 
152
- ### Image File Support
153
180
  ```ruby
154
181
  IMAGE_EXTENSIONS = %w[.jpg .jpeg .png .gif .bmp .webp].freeze
155
182
  IMAGE_GLOB_PATTERN = '*.{jpg,jpeg,png,gif,bmp,webp}'.freeze
156
- ```
183
+ INFO_FILENAMES = %w[ComicInfo.xml MetronInfo.xml].freeze
184
+
185
+ TYPES = %i[cb cb7 cba cbr cbt cbz folder pdf].freeze
186
+ READABLE_TYPES = %i[cb cb7 cbr cbt cbz folder pdf].freeze
187
+ WRITABLE_TYPES = %i[cb cb7 cbt cbz].freeze
157
188
 
158
- The system automatically filters files to include only recognized image formats when creating or extracting archives.
189
+ DEFAULT_PAGE_FILENAME_TEMPLATE = 'page_{page:3}'.freeze
190
+ ```
159
191
 
160
192
  ### 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
193
+
194
+ Archive options:
195
+ - `to`: Output path; its extension picks the format (default `.cbz` next to the source folder)
196
+ - `contents`: `:all` (default), `:images`, or `:images_and_info`
197
+ - `extension`: File extension for the default output path
198
+ - `delete_original`: Remove the source folder afterwards
199
+
200
+ Extract options:
201
+ - `to`: Destination folder (default: a `.cb` folder next to the archive)
202
+ - `images_only`: Extract only image files
203
+ - `extension`: Folder extension for the default destination
204
+ - `delete_original`: Remove the source archive afterwards
205
+ - `dpi`: PDF render resolution (default 300)
165
206
 
166
207
  ## Dependencies
167
208
 
168
209
  ### Runtime Dependencies
169
- - **rubyzip** (>= 3.2.1): ZIP file handling for CBZ format
210
+ - **comicinfo** (>= 2.1): Reads and updates `ComicInfo.xml`, and fills in page file name templates
211
+ - **rubyzip** (>= 3.4.0): ZIP file handling for CBZ format
170
212
  - **seven-zip** (~> 1.4): 7-Zip handling for CB7 format
213
+ - **ruby-vips** (>= 2.3): PDF rendering; loaded only when a PDF is used, and needs libvips on the system
171
214
  - Ruby stdlib: TAR handling for CBT format
215
+ - `lsar` / `unar`: RAR handling for CBR format (vendored for macOS and Windows)
172
216
 
173
217
  ### Development Dependencies
174
218
  - **rspec**: Testing framework
175
219
  - **rspec-file_fixtures**: Fixture management for tests
176
- - **rubocop**: Code linting and style enforcement
220
+ - **rubocop** (with `rubocop-performance`, `rubocop-rake`, `rubocop-rspec`): Code linting and style enforcement
177
221
 
178
222
  ## Testing Strategy
179
223
 
@@ -188,48 +232,29 @@ All tests use `Dir.mktmpdir` for file I/O operations to ensure:
188
232
  - Proper cleanup after each test
189
233
  - Isolation between test runs
190
234
 
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
235
  ## Error Handling
209
236
 
210
- ### Exception Hierarchy
211
237
  ```ruby
212
238
  ComicBook::Error < StandardError
213
239
  ```
214
240
 
215
241
  ### Common Error Cases
216
242
  - Unsupported file types
217
- - Missing dependencies for format handlers
218
- - Invalid or corrupted archive files
219
- - Permission issues during file operations
243
+ - Path does not exist
244
+ - Archiving a file, or extracting a folder
245
+ - Archiving to CBR, CBA, or PDF
246
+ - Any CBA operation (not yet implemented)
247
+ - `lsar` / `unar` failing or missing
248
+ - libvips missing when a PDF is used
220
249
 
221
- ## Future Extensibility
250
+ ## Adding New Formats
222
251
 
223
- ### Adding New Formats
224
252
  1. Create new adapter class inheriting from `ComicBook::Adapter`
225
253
  2. Implement archiver and extractor classes
226
254
  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.
255
+ 4. Add specs following existing patterns
231
256
 
232
257
  ## Version Information
233
- - **Current Version**: 0.2.0
234
- - **Ruby Requirement**: >= 4.0.0
258
+ - **Version**: see `lib/comic_book/version.rb`
259
+ - **Ruby Requirement**: >= 4.0.9
235
260
  - **License**: MIT
@@ -1,6 +1,6 @@
1
1
  # NOTE: don't use ComicBook::Adapter.new directly
2
2
  # Inherit from it when making an adapter to formats:
3
- # .cb7 .cba .cbr .cbt .cbz
3
+ # .cb .cb7 .cba .cbr .cbt .cbz .pdf
4
4
  class ComicBook
5
5
  class Adapter
6
6
  def initialize path
@@ -11,18 +11,25 @@ class ComicBook
11
11
  raise NotImplementedError, "#{self.class} must implement #archive"
12
12
  end
13
13
 
14
- def extract options = {}
15
- raise NotImplementedError, "#{self.class} must implement #extract"
14
+ def entries
15
+ raise NotImplementedError, "#{self.class} must implement #entries"
16
16
  end
17
17
 
18
- def pages
19
- raise NotImplementedError, "#{self.class} must implement #pages"
18
+ def extract options = {}
19
+ raise NotImplementedError, "#{self.class} must implement #extract"
20
20
  end
21
21
 
22
22
  def info
23
23
  raise NotImplementedError, "#{self.class} must implement #info"
24
24
  end
25
25
 
26
+ def images = entries.select(&:image?)
27
+ def images_and_info = entries.select { it.image? || it.info? }
28
+
29
+ def pages
30
+ raise NotImplementedError, "#{self.class} must implement #pages"
31
+ end
32
+
26
33
  private
27
34
 
28
35
  attr_reader :path