@ridi/comic-parser
Common comic data parser for Ridibooks services
Features
Install
npm install @ridi/comic-parser
Usage
Basic:
import { ComicParser } from '@ridi/comic-parser';
const parser = new ComicParser('./foo/bar.zip' or './unzippedPath');
parser.parse().then((items) => {
parser.readItems(items).then((results) => {
...
});
...
});
with Cryptor:
import { CryptoProvider, Cryptor } from '@ridi/comic-parser';
const { Purpose } = CryptoProvider;
const { Modes, Padding } = Cryptor;
class ContentCryptoProvider extends CryptoProvider {
constructor(key) {
super();
this.cryptor = new Cryptor(Modes.ECB, { key });
}
getCryptor(filePath, purpose) {
return this.cryptor;
}
run(data, filePath, purpose) {
const cryptor = this.getCryptor(filePath, purpose);
const padding = Padding.AUTO;
if (purpose === Purpose.READ_IN_DIR) {
return cryptor.decrypt(data, padding);
} else if (purpose === Purpose.WRITE) {
return cryptor.encrypt(data, padding);
}
return data;
}
}
const cryptoProvider = new ContentCryptoProvider(key);
const parser = new ComicParser('./encrypted.zip' or './unzippedPath', cryptoProvider);
Log level setting:
import { LogLevel, ... } from '@ridi/comic-parser';
parser.logger.logLevel = LogLevel.VERBOSE;
API
parse(parseOptions)
Returns Promise<ComicBook>
with:
- ComicBook: Instance with image path, size, etc.
Or throw exception.
readItem(item, readOptions)
Returns string
or Buffer
in Promise
with:
or throw exception.
readItems(items, readOptions)
Returns string[]
or Buffer[]
in Promise
with:
or throw exception.
onProgress = callback(step, totalStep, action)
Tells the progress of parser through callback
.
const { Action } = ComicParser;
parser.onProgress = (step, totalStep, action) => {
console.log(`[${action}] ${step} / ${totalStep}`);
}
Model
- index: ?string
- path: ?string
- fileSize: ?number
- width: ?number
- height: ?number
Parse Options
unzipPath: ?string
If specified, unzip to that path.
only using if input is Zip file.
Default: undefined
overwrite: boolean
If true, overwrite to unzipPath when unzip.
only using if unzipPath specified.
Default: true
ext: string[]
File extension to allow when extracting lists.
Default: ['jpg', 'jpeg', 'png', 'bmp', 'gif']
parseImageSize: boolean|number
If true, image size parse. (parse may be slower.)
Default: false
Read Options
force: boolean
If true, ignore any exceptions that occur within parser.
Default: false
base64: boolean
If false, reads image into a buffer.
Default: false
License
MIT