@mdgate/mobi 0.6.8 → 0.6.10
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/README.md +153 -15
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# @mdgate/mobi
|
|
2
2
|
|
|
3
|
-
Convert
|
|
4
|
-
Node, Edge, and browsers. No native addons.
|
|
3
|
+
**Convert MOBI and Kindle ebooks to Markdown in TypeScript.**
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[`@mdgate/mobi`](https://github.com/mdgate/converters/tree/main/packages/mobi) reads `.mobi`, `.azw`, `.azw3`, and `.prc` files directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or Kindle software.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mdgate/mobi
|
|
11
|
+
```
|
|
9
12
|
|
|
10
13
|
```ts
|
|
11
14
|
import { toMarkdown } from '@mdgate/mobi';
|
|
@@ -13,23 +16,158 @@ import { toMarkdown } from '@mdgate/mobi';
|
|
|
13
16
|
const markdown = await toMarkdown(bytes);
|
|
14
17
|
```
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
`bytes` is a `Uint8Array`, so the book can come from a file upload, object storage, an HTTP request, a browser file picker, or anywhere else your application gets bytes.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Why [`@mdgate/mobi`](https://github.com/mdgate/converters/tree/main/packages/mobi)
|
|
24
|
+
|
|
25
|
+
MOBI and KF8/AZW3 are binary Palm databases, not EPUB. A ZIP/HTML parser will not read them.
|
|
26
|
+
|
|
27
|
+
[`@mdgate/mobi`](https://github.com/mdgate/converters/tree/main/packages/mobi) is a MOBI reader written for the same runtime as your application:
|
|
28
|
+
|
|
29
|
+
* **Pure TypeScript**
|
|
30
|
+
* **MOBI → Markdown locally**
|
|
31
|
+
* **No Python runtime**
|
|
32
|
+
* **No native addons**
|
|
33
|
+
* **No WASM runtime**
|
|
34
|
+
* **Zero third-party runtime dependencies**
|
|
35
|
+
* **Works with raw `Uint8Array` input**
|
|
36
|
+
* **Detects PalmDB / MOBI headers from their contents, not only the filename**
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## What it extracts
|
|
41
|
+
|
|
42
|
+
[`@mdgate/mobi`](https://github.com/mdgate/converters/tree/main/packages/mobi) reads PalmDOC and MOBI text records.
|
|
43
|
+
|
|
44
|
+
Supported compression:
|
|
45
|
+
|
|
46
|
+
* uncompressed PalmDOC
|
|
47
|
+
* PalmDOC LZ77
|
|
48
|
+
* HUFF/CDIC
|
|
49
|
+
|
|
50
|
+
KF8/AZW3 XHTML is converted when it can be isolated from the text stream. Skeleton + fragment reconstruction via INDX is not implemented, so some AZW3 books lose structure.
|
|
51
|
+
|
|
52
|
+
Not extracted:
|
|
53
|
+
|
|
54
|
+
* images, fonts, and audio
|
|
55
|
+
* NCX / table-of-contents indexes
|
|
56
|
+
* Topaz (`TPZ`) Kindle files
|
|
57
|
+
|
|
58
|
+
DRM-encrypted books fail with `ConvertError.encrypted`.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Node.js
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { readFile } from 'node:fs/promises';
|
|
66
|
+
import { toMarkdown } from '@mdgate/mobi';
|
|
67
|
+
|
|
68
|
+
const bytes = new Uint8Array(await readFile('book.mobi'));
|
|
69
|
+
const markdown = await toMarkdown(bytes);
|
|
70
|
+
|
|
71
|
+
console.log(markdown);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Browser
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { toMarkdown } from '@mdgate/mobi';
|
|
80
|
+
|
|
81
|
+
const file = input.files![0];
|
|
82
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
83
|
+
|
|
84
|
+
const markdown = await toMarkdown(bytes);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Cloudflare Workers and Edge runtimes
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { toMarkdown } from '@mdgate/mobi';
|
|
93
|
+
|
|
94
|
+
export default {
|
|
95
|
+
async fetch(request: Request) {
|
|
96
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
97
|
+
const markdown = await toMarkdown(bytes);
|
|
98
|
+
|
|
99
|
+
return new Response(markdown, {
|
|
100
|
+
headers: {
|
|
101
|
+
'content-type': 'text/markdown; charset=utf-8',
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Format detection
|
|
111
|
+
|
|
112
|
+
You do not need to trust the file extension.
|
|
113
|
+
|
|
114
|
+
[`@mdgate/mobi`](https://github.com/mdgate/converters/tree/main/packages/mobi) recognizes PalmDB / MOBI headers from the bytes.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const markdown = await toMarkdown(bytes);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
A path can still be supplied as a format hint when [`@mdgate/mobi`](https://github.com/mdgate/converters/tree/main/packages/mobi) is used through [`@mdgate/converters`](https://github.com/mdgate/converters/tree/main/packages/converters) or a reader composed with [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core), but the path is never used to read a file from disk.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Encrypted books
|
|
125
|
+
|
|
126
|
+
DRM-encrypted books are reported as encrypted rather than returning misleading partial output.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Compose it with other file readers
|
|
131
|
+
|
|
132
|
+
[`@mdgate/mobi`](https://github.com/mdgate/converters/tree/main/packages/mobi) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
|
|
17
133
|
|
|
18
134
|
```ts
|
|
19
135
|
import { create } from '@mdgate/core';
|
|
20
136
|
import { mobi } from '@mdgate/mobi';
|
|
137
|
+
import { epub } from '@mdgate/epub';
|
|
21
138
|
|
|
22
|
-
const
|
|
139
|
+
const read = create([
|
|
140
|
+
mobi(),
|
|
141
|
+
epub(),
|
|
142
|
+
]);
|
|
23
143
|
```
|
|
24
144
|
|
|
25
|
-
|
|
26
|
-
|
|
145
|
+
The application still uses one reading interface while each format remains independently installable.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Need more than MOBI?
|
|
150
|
+
|
|
151
|
+
If your application needs to read many different file types, use the complete converter set:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
npm install @mdgate/converters
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { toMarkdown } from '@mdgate/converters';
|
|
159
|
+
|
|
160
|
+
const markdown = await toMarkdown(bytes, {
|
|
161
|
+
path: filename,
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
[`@mdgate/mobi`](https://github.com/mdgate/converters/tree/main/packages/mobi) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
166
|
+
|
|
167
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
168
|
+
|
|
169
|
+
---
|
|
27
170
|
|
|
28
|
-
##
|
|
171
|
+
## License
|
|
29
172
|
|
|
30
|
-
|
|
31
|
-
- Text records are extracted: uncompressed PalmDOC, PalmDOC LZ77, and HUFF/CDIC.
|
|
32
|
-
- KF8/AZW3 XHTML is converted when it can be isolated from the text stream. Skeleton + fragment
|
|
33
|
-
reconstruction via INDX is not implemented, so some AZW3 books lose structure.
|
|
34
|
-
- Images, fonts, audio, and NCX/toc indexes are not extracted.
|
|
35
|
-
- Topaz (`TPZ`) Kindle files are not supported.
|
|
173
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/mobi",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "mdgate MOBI / AZW3 converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://convert.mdgate.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/mdgate/converters.git",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"prepublishOnly": "bun run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mdgate/containers": "0.6.
|
|
32
|
-
"@mdgate/core": "0.6.
|
|
33
|
-
"@mdgate/document": "0.6.
|
|
34
|
-
"@mdgate/html": "0.6.
|
|
35
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/containers": "0.6.10",
|
|
32
|
+
"@mdgate/core": "0.6.10",
|
|
33
|
+
"@mdgate/document": "0.6.10",
|
|
34
|
+
"@mdgate/html": "0.6.10",
|
|
35
|
+
"@mdgate/utils": "0.6.10"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|