Skip to content

Commit

Permalink
Merge pull request #33 from ridi/pdf-parser
Browse files Browse the repository at this point in the history
Add Pdf parser package and improve cryption performance
  • Loading branch information
DavinAhn committed Aug 4, 2019
2 parents a6ffa77 + 8c1f1d0 commit eb10437
Show file tree
Hide file tree
Showing 177 changed files with 2,597 additions and 453 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

* Add `pdf-parser` package.
* Add `EpubParser.parseOptions.additionalInlineStyle` option. (default: `undefined`)
* Add `CryptoProvider.bufferSize` property.

### Changed

* Remove `Version.isValid` property.
* Improve cryption performance.

## [0.5.8 (2019-07-03)]

Expand Down
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Packages

## [@ridi/parser-core](packages/parser-core)

> Utilities for parsers
Expand All @@ -10,7 +12,7 @@

## [@ridi/content-parser](packages/content-parser)

> Content data parser for Ridibooks services (epub-parser + comic-parser)
> Content data parser for Ridibooks services (epub-parser + comic-parser + pdf-parser)
[![NPM version](https://badge.fury.io/js/%40ridi%2Fcontent-parser.svg)](https://badge.fury.io/js/%40ridi%2Fcontent-parser)
[![Build Status](https://travis-ci.org/ridi/content-parser.svg?branch=master)](https://travis-ci.org/ridi/content-parser)
Expand All @@ -37,3 +39,58 @@
[![codecov](https://codecov.io/gh/ridi/content-parser/branch/master/graph/badge.svg)](https://codecov.io/gh/ridi/content-parser)
[![NPM total downloads](https://img.shields.io/npm/dt/%40ridi%2Fcomic-parser.svg)](https://npm.im/%40ridi%2Fcomic-parser)
[![Greenkeeper badge](https://badges.greenkeeper.io/ridi/content-parser.svg)](https://greenkeeper.io/)

## [@ridi/pdf-parser](packages/pdf-parser)

> Common PDF data parser for Ridibooks services
[![NPM version](https://badge.fury.io/js/%40ridi%2Fpdf-parser.svg)](https://badge.fury.io/js/%40ridi%2Fpdf-parser)
[![Build Status](https://travis-ci.org/ridi/content-parser.svg?branch=master)](https://travis-ci.org/ridi/content-parser)
[![codecov](https://codecov.io/gh/ridi/content-parser/branch/master/graph/badge.svg)](https://codecov.io/gh/ridi/content-parser)
[![NPM total downloads](https://img.shields.io/npm/dt/%40ridi%2Fpdf-parser.svg)](https://npm.im/%40ridi%2Fpdf-parser)
[![Greenkeeper badge](https://badges.greenkeeper.io/ridi/content-parser.svg)](https://greenkeeper.io/)

# Development

## Setup

```
$ git clone git@github.com:ridi/content-parser.git
$ yarn
```
> [yarn](https://yarnpkg.com) required.
## Commands

If you want install the development environment or add a new dependency to the package or add a new package, run the following command:

```
$ yarn
```

If you want only build, the following command:

```
$ yarn build
```
> `yarn clean` are preceded.
If you want only lint, the following command:

```
$ yarn lint
```

To test each package, use the following command:

```
$ yarn test
```
> `yarn build` and `yarn lint` are preceded.
To deploy the new version, use the following command:

```
$ yarn bump
```
> Version names must conform to [SemVer](https://semver.org).
3 changes: 2 additions & 1 deletion greenkeeper.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"packages/comic-parser/package.json",
"packages/content-parser/package.json",
"packages/epub-parser/package.json",
"packages/parser-core/package.json"
"packages/parser-core/package.json",
"packages/pdf-parser/package.json"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
"packages/*"
],
"version": "0.5.8",
"version": "0.6.0-alpha.8",
"command": {
"publish": {
"message": "Bump version to %v",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"scripts": {
"clean": "rimraf ./*.log && lerna exec --parallel -- rimraf coverage lib/* temp",
"build": "yarn clean && lerna exec --parallel -- babel src --out-dir lib --config-file ../../.babelrc",
"test": "yarn build && yarn lint && lerna exec --parallel -- nyc mocha --recursive",
"test": "yarn build && yarn lint && lerna exec --concurrency 1 -- nyc mocha --recursive",
"coverage": "codecov",
"lint": "eslint packages",
"postinstall": "yarn build && yarn bootstrap",
Expand All @@ -15,7 +15,6 @@
"devDependencies": {
"@babel/runtime": "^7.5.5",
"@ridi/eslint-config": "^4.1.0",
"codecov": "^3.1.0",
"babel-cli": "^6.26.0",
"babel-eslint": "^10.0.1",
"babel-plugin-add-module-exports": "^1.0.2",
Expand All @@ -24,6 +23,7 @@
"babel-preset-env": "^1.7.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"codecov": "^3.1.0",
"eslint": "^6.0.0",
"eslint-config-airbnb": "^17.0.0",
"eslint-plugin-import": "^2.17.2",
Expand Down
2 changes: 1 addition & 1 deletion LICENSE → packages/comic-parser/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 RIDI
Copyright (c) 2019 RIDI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 8 additions & 6 deletions packages/comic-parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { ComicParser } from '@ridi/comic-parser';
// or const { ComicParser } = require('@ridi/comic-parser');

const parser = new ComicParser('./foo/bar.zip' or './unzippedPath');
parser.parse(/* { parseOptions } */).then((items) => {
parser.parse(/* { parseOptions } */).then((book) => {
parser.readItems(items/*, { readOptions } */).then((results) => {
...
});
Expand All @@ -53,12 +53,12 @@ import { CryptoProvider, AesCryptor } from '@ridi/comic-parser';
// or const { CryptoProvider, AesCryptor } = require('@ridi/comic-parser');

const { Purpose } = CryptoProvider;
const { Modes, Padding } = AesCryptor;
const { Mode, Padding } = AesCryptor;

class ContentCryptoProvider extends CryptoProvider {
constructor(key) {
super();
this.cryptor = new AesCryptor(Modes.ECB, { key });
this.cryptor = new AesCryptor(Mode.ECB, { key });
}

getCryptor(filePath, purpose) {
Expand All @@ -83,9 +83,9 @@ class ContentCryptoProvider extends CryptoProvider {
const cryptor = this.getCryptor(filePath, purpose);
const padding = Padding.AUTO;
if (purpose === Purpose.READ_IN_DIR) {
return cryptor.decrypt(data, padding);
return cryptor.decrypt(data, { padding });
} else if (purpose === Purpose.WRITE) {
return cryptor.encrypt(data, padding);
return cryptor.encrypt(data, { padding });
}
return data;
}
Expand Down Expand Up @@ -190,6 +190,7 @@ parser.onProgress = (step, totalStep, action) => {
### [ComicBook](./src/model/Book.js)

- items: *[Item](#item)[]*
- toRaw(): *object*

<a id="item"></a>

Expand All @@ -200,6 +201,7 @@ parser.onProgress = (step, totalStep, action) => {
- fileSize: *?number*
- width: *?number*
- height: *?number*
- toRaw(): *object*

<a id="parseOptions"></a>

Expand Down Expand Up @@ -281,4 +283,4 @@ If false, reads image into a buffer.

## License

[MIT](https://github.com/ridi/content-parser/blob/master/LICENSE)
[MIT](https://github.com/ridi/content-parser/packages/comic-parser/LICENSE)
4 changes: 2 additions & 2 deletions packages/comic-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ridi/comic-parser",
"version": "0.5.8",
"version": "0.6.0-alpha.8",
"description": "Common comic data parser for Ridibooks services",
"author": {
"name": "Ridibooks Viewer Team",
Expand All @@ -18,7 +18,7 @@
],
"main": "lib/index.js",
"dependencies": {
"@ridi/parser-core": "^0.5.8",
"@ridi/parser-core": "^0.6.0-alpha.8",
"fs-extra": "^8.0.0",
"image-size": "^0.7.1",
"string-natural-compare": "^2.0.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/comic-parser/src/ComicParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class ComicParser extends Parser {
* @param {ReadContext} context properties required for reading
* @returns {(string|Buffer)[]} reading results
* @throws {Errors.ENOFILE} no such file
* @see ComicParser.readDefaultOptions.force
* @see ComicParser.readDefaultOptions.base64
*/
async _read(context) {
const { items, entries, options } = context;
Expand Down
1 change: 1 addition & 0 deletions packages/comic-parser/src/model/ParseContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Book from './Book';
class Context {
constructor() {
this.options = undefined;
this.entries = undefined;
const rawBook = {};
Object.keys(new Book()).forEach((key) => { rawBook[key] = undefined; });
this.rawBook = rawBook;
Expand Down
6 changes: 4 additions & 2 deletions packages/comic-parser/test/ComicParser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ describe('ComicParser', () => {
});
});

it('Use parseImageSize option (boolean)', () => {
it('Use parseImageSize option (boolean)', function () {
this.timeout(5 * 1000);
const parseOptions = { parseImageSize: true };
return new ComicParser(Paths.UNZIPPED_COMIC).parse(parseOptions).then(book => {
validationBook(book, JSON.parse(fs.readFileSync(Paths.EXPECTED_COMIC_BOOK_WITH_SIZE)), parseOptions);
});
});

it('Use parseImageSize option (number)', () => {
it('Use parseImageSize option (number)', function () {
this.timeout(5 * 1000);
const parseOptions = { parseImageSize: 1024 * 50 };
return new ComicParser(Paths.UNZIPPED_COMIC).parse(parseOptions).then(book => {
validationBook(book, JSON.parse(fs.readFileSync(Paths.EXPECTED_COMIC_BOOK_WITH_SIZE)), parseOptions);
Expand Down
Loading

0 comments on commit eb10437

Please sign in to comment.