@clearmist-labs/comic-archive-handler 1.4.0 → 1.6.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.
package/docs/API.md CHANGED
@@ -58,6 +58,7 @@ Converts an archive to `zip`, `rar`, `tar`, `asar`, or `7z`. Entries are copied
58
58
  - `options.image?: { format: ImageOutputFormat; options?: ImageConvertOptions }` - Re-encode image entries while converting the archive.
59
59
  - `options.image.format` - `'webp'`, `'jpg'`, or `'png'`.
60
60
  - `options.image.options` - Image format options described under [`convertImageBuffer`](#convertimagebuffer).
61
+ - `options.metadata?: Partial<Record<MetadataSchema, ComicMetadata>>` - Replaces the source's embedded comic metadata. The source's `ComicInfo.xml`/`MetronInfo.xml` entries are dropped (an ASAR source's header metadata is never copied), then each given schema is written as an ASAR header key when the target is `asar`, or as a root-level `ComicInfo.xml`/`MetronInfo.xml` entry otherwise. Without it, an ASAR source's header metadata is not carried into the output.
61
62
 
62
63
  **Example**
63
64
 
@@ -68,6 +69,10 @@ const output = await convertArchive('/books/example.cbr', 'zip', {
68
69
  output: '/books/example.cbz',
69
70
  image: { format: 'webp', options: { webp: { quality: 92 } } },
70
71
  });
72
+
73
+ // Move a ComicInfo.xml entry into the ASAR header
74
+ const { metadata } = await readArchiveMetadata('/books/example.cbz', 'ComicInfo');
75
+ await convertArchive('/books/example.cbz', 'asar', { output: '/books/example.cbas', metadata: { ComicInfo: metadata } });
71
76
  ```
72
77
 
73
78
  ### `listArchiveFiles(input)`
@@ -116,6 +121,21 @@ for await (const entry of cah.readArchiveEntries(comicBuffer)) {
116
121
  }
117
122
  ```
118
123
 
124
+ ### `readArchiveImageInfo(input)`
125
+
126
+ Returns `{ name, path, width, height, type }` for every image entry in an archive, in archive iteration order. Image entries are identified by extension (see `isImagePath`), and non-image entries are skipped without being read. `name` is the file name without its directory, and `type` is the format detected from the entry's contents rather than its extension (`jpeg`, `png`, `gif`, `webp`, `tiff`, `bmp`, and so on). When an entry's contents are not a readable image, `width`, `height`, and `type` are `null`.
127
+
128
+ **Options**
129
+
130
+ - `input: ArchiveInput` - A filesystem path or archive `Buffer`.
131
+
132
+ **Example**
133
+
134
+ ```js
135
+ const images = await cah.readArchiveImageInfo(comicBuffer);
136
+ console.log(images[0]); // { name: 'P00001.jpg', path: 'pages/P00001.jpg', width: 1988, height: 3056, type: 'jpeg' }
137
+ ```
138
+
119
139
  ### `renameArchiveImagesSequentially(input, options?)`
120
140
 
121
141
  Renames image entries in natural-sort order to `P#####.<extension>`, while leaving other entries unchanged.
@@ -485,6 +505,34 @@ Returns whether an archive entry path has an extension in `IMAGE_EXTENSIONS`.
485
505
  if (cah.isImagePath('P00001.jpg')) console.log('page image');
486
506
  ```
487
507
 
508
+ ### `readImageInfo(image)`
509
+
510
+ Reads an image's format and pixel dimensions from its header without decoding it, returning `{ width, height, type }`. Returns `null` when the buffer is not a readable image.
511
+
512
+ **Options**
513
+
514
+ - `image: Buffer` - Image bytes.
515
+
516
+ **Example**
517
+
518
+ ```js
519
+ const info = await cah.readImageInfo(imageBytes); // { width: 1988, height: 3056, type: 'jpeg' }
520
+ ```
521
+
522
+ ### `readImageDimensions(image)`
523
+
524
+ Like `readImageInfo`, but returns only `{ width, height }`.
525
+
526
+ **Options**
527
+
528
+ - `image: Buffer` - Image bytes.
529
+
530
+ **Example**
531
+
532
+ ```js
533
+ const { width, height } = await cah.readImageDimensions(imageBytes);
534
+ ```
535
+
488
536
  ## Perceptual hashing
489
537
 
490
538
  ### `computeImagePHash(image)`
@@ -672,6 +720,9 @@ The following types are exported for TypeScript consumers.
672
720
  - `MetadataValidationResult` - `{ valid: boolean; issues: MetadataValidationIssue[] }`, returned by `validateMetadataXml`.
673
721
  - `MetadataValidationIssue` - `{ message: string; line?: number }`.
674
722
  - `ExtractArchiveOptions` - `{ tempDir?: string }`.
723
+ - `ArchiveImageInfo` - `{ name, path, width, height, type }`, returned by `readArchiveImageInfo`. `width`, `height`, and `type` are `null` for unreadable images.
724
+ - `ImageDimensions` - `{ width: number; height: number }`.
725
+ - `ImageInfo` - `ImageDimensions & { type: string }`, returned by `readImageInfo`.
675
726
  - `WritableArchiveType` - `'zip' | 'tar' | 'asar' | '7z'`.
676
727
  - `BenchmarkArchiveOptions` - `{ tempDir?, reportsDir?, creationIterations?, seekSamples?, imageFormats?, image? }`; see [`benchmarkArchive`](#benchmarkarchivefilepath-options).
677
728
  - `BenchmarkVariantResult` - One generated variant's stats: `{ archiveType, imageFormat, fileName, filePath, fileSizeBytes, pageCount, avgImageSizeBytes, avgCreationMs, avgSeekMs }`. `avgImageSizeBytes` (average size of one converted page) depends only on `imageFormat`, not `archiveType`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clearmist-labs/comic-archive-handler",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Detect, convert, and manipulate comic book archives: container conversion, edit metadata, image re-encoding, perceptual + content hashing.",
5
5
  "keywords": [
6
6
  "7z",