@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);
API
parse(parseOptions)
Returns Promise<Book>
with:
- Book: 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.
Model
- index: ?string
- path: ?string
- size: ?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']
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