@swc/anyformat-pdf 0.1.3 → 0.2.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/binding.d.ts +55 -2
- package/binding.js +63 -56
- package/index.d.ts +70 -1
- package/index.js +18 -2
- package/package.json +25 -16
package/binding.d.ts
CHANGED
|
@@ -9,13 +9,66 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Reads the version, for example `"1.7"`, from the PDF header of `data`, on
|
|
14
|
+
* the thread pool. Copies only the first 1031 bytes, so the caller can
|
|
15
|
+
* change `data` after the call.
|
|
16
|
+
*
|
|
17
|
+
* Returns `null` when the first 1024 bytes of `data` do not contain a PDF
|
|
18
|
+
* header.
|
|
19
|
+
*/
|
|
20
|
+
export declare function detectVersion(data: Uint8Array): Promise<string | null>
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Reads the version, for example `"1.7"`, from the PDF header of the file at
|
|
24
|
+
* `path`, on the thread pool. Reads only the first 1031 bytes.
|
|
25
|
+
*
|
|
26
|
+
* Returns `null` when the first 1024 bytes of the file do not contain a PDF
|
|
27
|
+
* header.
|
|
28
|
+
*/
|
|
29
|
+
export declare function detectVersionFile(path: string): Promise<string | null>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Reads the version, for example `"1.7"`, from the PDF header of the file at
|
|
33
|
+
* `path`. Reads only the first 1031 bytes.
|
|
34
|
+
*
|
|
35
|
+
* Returns `null` when the first 1024 bytes of the file do not contain a PDF
|
|
36
|
+
* header.
|
|
37
|
+
*/
|
|
38
|
+
export declare function detectVersionFileSync(path: string): string | null
|
|
39
|
+
|
|
12
40
|
/**
|
|
13
41
|
* Reads the version, for example `"1.7"`, from the PDF header of `data`.
|
|
14
42
|
*
|
|
15
43
|
* Returns `null` when the first 1024 bytes of `data` do not contain a PDF
|
|
16
44
|
* header.
|
|
17
45
|
*/
|
|
18
|
-
export declare function
|
|
46
|
+
export declare function detectVersionSync(data: Uint8Array): string | null
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The number of leading bytes that `isPdf` and `detectVersion` read. The
|
|
50
|
+
* public API uses it for `isPdfStream` and does not export it.
|
|
51
|
+
*/
|
|
52
|
+
export declare const HEADER_PREFIX_LEN: number
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns `true` when `data` starts with a PDF file header, on the thread
|
|
56
|
+
* pool. Copies only the first 1031 bytes, so the caller can change `data`
|
|
57
|
+
* after the call.
|
|
58
|
+
*/
|
|
59
|
+
export declare function isPdf(data: Uint8Array): Promise<boolean>
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Returns `true` when the file at `path` starts with a PDF file header, on
|
|
63
|
+
* the thread pool. Reads only the first 1031 bytes.
|
|
64
|
+
*/
|
|
65
|
+
export declare function isPdfFile(path: string): Promise<boolean>
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Returns `true` when the file at `path` starts with a PDF file header.
|
|
69
|
+
* Reads only the first 1031 bytes.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isPdfFileSync(path: string): boolean
|
|
19
72
|
|
|
20
73
|
/** Returns `true` when `data` starts with a PDF file header. */
|
|
21
|
-
export declare function
|
|
74
|
+
export declare function isPdfSync(data: Uint8Array): boolean
|
package/binding.js
CHANGED
|
@@ -94,8 +94,8 @@ function requireNative() {
|
|
|
94
94
|
try {
|
|
95
95
|
const binding = require('@swc/anyformat-pdf-android-arm64')
|
|
96
96
|
const bindingPackageVersion = require('@swc/anyformat-pdf-android-arm64/package.json').version
|
|
97
|
-
if (bindingPackageVersion !== '0.
|
|
98
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
97
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
98
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
99
99
|
}
|
|
100
100
|
return binding
|
|
101
101
|
} catch (e) {
|
|
@@ -110,8 +110,8 @@ function requireNative() {
|
|
|
110
110
|
try {
|
|
111
111
|
const binding = require('@swc/anyformat-pdf-android-arm-eabi')
|
|
112
112
|
const bindingPackageVersion = require('@swc/anyformat-pdf-android-arm-eabi/package.json').version
|
|
113
|
-
if (bindingPackageVersion !== '0.
|
|
114
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
113
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
114
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
115
115
|
}
|
|
116
116
|
return binding
|
|
117
117
|
} catch (e) {
|
|
@@ -131,8 +131,8 @@ function requireNative() {
|
|
|
131
131
|
try {
|
|
132
132
|
const binding = require('@swc/anyformat-pdf-win32-x64-gnu')
|
|
133
133
|
const bindingPackageVersion = require('@swc/anyformat-pdf-win32-x64-gnu/package.json').version
|
|
134
|
-
if (bindingPackageVersion !== '0.
|
|
135
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
134
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
135
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
136
136
|
}
|
|
137
137
|
return binding
|
|
138
138
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('@swc/anyformat-pdf-win32-x64-msvc')
|
|
149
149
|
const bindingPackageVersion = require('@swc/anyformat-pdf-win32-x64-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '0.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
150
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -164,8 +164,8 @@ function requireNative() {
|
|
|
164
164
|
try {
|
|
165
165
|
const binding = require('@swc/anyformat-pdf-win32-ia32-msvc')
|
|
166
166
|
const bindingPackageVersion = require('@swc/anyformat-pdf-win32-ia32-msvc/package.json').version
|
|
167
|
-
if (bindingPackageVersion !== '0.
|
|
168
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
167
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
168
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
169
169
|
}
|
|
170
170
|
return binding
|
|
171
171
|
} catch (e) {
|
|
@@ -180,8 +180,8 @@ function requireNative() {
|
|
|
180
180
|
try {
|
|
181
181
|
const binding = require('@swc/anyformat-pdf-win32-arm64-msvc')
|
|
182
182
|
const bindingPackageVersion = require('@swc/anyformat-pdf-win32-arm64-msvc/package.json').version
|
|
183
|
-
if (bindingPackageVersion !== '0.
|
|
184
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
183
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
184
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
185
185
|
}
|
|
186
186
|
return binding
|
|
187
187
|
} catch (e) {
|
|
@@ -199,8 +199,8 @@ function requireNative() {
|
|
|
199
199
|
try {
|
|
200
200
|
const binding = require('@swc/anyformat-pdf-darwin-universal')
|
|
201
201
|
const bindingPackageVersion = require('@swc/anyformat-pdf-darwin-universal/package.json').version
|
|
202
|
-
if (bindingPackageVersion !== '0.
|
|
203
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
202
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
203
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
204
204
|
}
|
|
205
205
|
return binding
|
|
206
206
|
} catch (e) {
|
|
@@ -215,8 +215,8 @@ function requireNative() {
|
|
|
215
215
|
try {
|
|
216
216
|
const binding = require('@swc/anyformat-pdf-darwin-x64')
|
|
217
217
|
const bindingPackageVersion = require('@swc/anyformat-pdf-darwin-x64/package.json').version
|
|
218
|
-
if (bindingPackageVersion !== '0.
|
|
219
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
218
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
219
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
220
220
|
}
|
|
221
221
|
return binding
|
|
222
222
|
} catch (e) {
|
|
@@ -231,8 +231,8 @@ function requireNative() {
|
|
|
231
231
|
try {
|
|
232
232
|
const binding = require('@swc/anyformat-pdf-darwin-arm64')
|
|
233
233
|
const bindingPackageVersion = require('@swc/anyformat-pdf-darwin-arm64/package.json').version
|
|
234
|
-
if (bindingPackageVersion !== '0.
|
|
235
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
234
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
235
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
236
236
|
}
|
|
237
237
|
return binding
|
|
238
238
|
} catch (e) {
|
|
@@ -251,8 +251,8 @@ function requireNative() {
|
|
|
251
251
|
try {
|
|
252
252
|
const binding = require('@swc/anyformat-pdf-freebsd-x64')
|
|
253
253
|
const bindingPackageVersion = require('@swc/anyformat-pdf-freebsd-x64/package.json').version
|
|
254
|
-
if (bindingPackageVersion !== '0.
|
|
255
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
254
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
255
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
256
256
|
}
|
|
257
257
|
return binding
|
|
258
258
|
} catch (e) {
|
|
@@ -267,8 +267,8 @@ function requireNative() {
|
|
|
267
267
|
try {
|
|
268
268
|
const binding = require('@swc/anyformat-pdf-freebsd-arm64')
|
|
269
269
|
const bindingPackageVersion = require('@swc/anyformat-pdf-freebsd-arm64/package.json').version
|
|
270
|
-
if (bindingPackageVersion !== '0.
|
|
271
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
270
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
271
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
272
272
|
}
|
|
273
273
|
return binding
|
|
274
274
|
} catch (e) {
|
|
@@ -283,8 +283,8 @@ function requireNative() {
|
|
|
283
283
|
try {
|
|
284
284
|
const binding = require('@swc/anyformat-pdf-freebsd-ppc64')
|
|
285
285
|
const bindingPackageVersion = require('@swc/anyformat-pdf-freebsd-ppc64/package.json').version
|
|
286
|
-
if (bindingPackageVersion !== '0.
|
|
287
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
286
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
287
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
288
288
|
}
|
|
289
289
|
return binding
|
|
290
290
|
} catch (e) {
|
|
@@ -304,8 +304,8 @@ function requireNative() {
|
|
|
304
304
|
try {
|
|
305
305
|
const binding = require('@swc/anyformat-pdf-linux-x64-musl')
|
|
306
306
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-x64-musl/package.json').version
|
|
307
|
-
if (bindingPackageVersion !== '0.
|
|
308
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
307
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
308
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
309
309
|
}
|
|
310
310
|
return binding
|
|
311
311
|
} catch (e) {
|
|
@@ -320,8 +320,8 @@ function requireNative() {
|
|
|
320
320
|
try {
|
|
321
321
|
const binding = require('@swc/anyformat-pdf-linux-x64-gnu')
|
|
322
322
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-x64-gnu/package.json').version
|
|
323
|
-
if (bindingPackageVersion !== '0.
|
|
324
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
323
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
324
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
325
325
|
}
|
|
326
326
|
return binding
|
|
327
327
|
} catch (e) {
|
|
@@ -338,8 +338,8 @@ function requireNative() {
|
|
|
338
338
|
try {
|
|
339
339
|
const binding = require('@swc/anyformat-pdf-linux-arm64-musl')
|
|
340
340
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-arm64-musl/package.json').version
|
|
341
|
-
if (bindingPackageVersion !== '0.
|
|
342
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
341
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
342
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
343
343
|
}
|
|
344
344
|
return binding
|
|
345
345
|
} catch (e) {
|
|
@@ -354,8 +354,8 @@ function requireNative() {
|
|
|
354
354
|
try {
|
|
355
355
|
const binding = require('@swc/anyformat-pdf-linux-arm64-gnu')
|
|
356
356
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-arm64-gnu/package.json').version
|
|
357
|
-
if (bindingPackageVersion !== '0.
|
|
358
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
357
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
358
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
359
359
|
}
|
|
360
360
|
return binding
|
|
361
361
|
} catch (e) {
|
|
@@ -372,8 +372,8 @@ function requireNative() {
|
|
|
372
372
|
try {
|
|
373
373
|
const binding = require('@swc/anyformat-pdf-linux-arm-musleabihf')
|
|
374
374
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-arm-musleabihf/package.json').version
|
|
375
|
-
if (bindingPackageVersion !== '0.
|
|
376
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
375
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
376
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
377
377
|
}
|
|
378
378
|
return binding
|
|
379
379
|
} catch (e) {
|
|
@@ -388,8 +388,8 @@ function requireNative() {
|
|
|
388
388
|
try {
|
|
389
389
|
const binding = require('@swc/anyformat-pdf-linux-arm-gnueabihf')
|
|
390
390
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-arm-gnueabihf/package.json').version
|
|
391
|
-
if (bindingPackageVersion !== '0.
|
|
392
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
391
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
392
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
393
393
|
}
|
|
394
394
|
return binding
|
|
395
395
|
} catch (e) {
|
|
@@ -406,8 +406,8 @@ function requireNative() {
|
|
|
406
406
|
try {
|
|
407
407
|
const binding = require('@swc/anyformat-pdf-linux-loong64-musl')
|
|
408
408
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-loong64-musl/package.json').version
|
|
409
|
-
if (bindingPackageVersion !== '0.
|
|
410
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
409
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
410
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
411
411
|
}
|
|
412
412
|
return binding
|
|
413
413
|
} catch (e) {
|
|
@@ -422,8 +422,8 @@ function requireNative() {
|
|
|
422
422
|
try {
|
|
423
423
|
const binding = require('@swc/anyformat-pdf-linux-loong64-gnu')
|
|
424
424
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-loong64-gnu/package.json').version
|
|
425
|
-
if (bindingPackageVersion !== '0.
|
|
426
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
425
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
426
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
427
427
|
}
|
|
428
428
|
return binding
|
|
429
429
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('@swc/anyformat-pdf-linux-riscv64-musl')
|
|
442
442
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-riscv64-musl/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '0.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
443
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('@swc/anyformat-pdf-linux-riscv64-gnu')
|
|
458
458
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-riscv64-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '0.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
459
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -473,8 +473,8 @@ function requireNative() {
|
|
|
473
473
|
try {
|
|
474
474
|
const binding = require('@swc/anyformat-pdf-linux-ppc64-gnu')
|
|
475
475
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-ppc64-gnu/package.json').version
|
|
476
|
-
if (bindingPackageVersion !== '0.
|
|
477
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
476
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
477
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
478
478
|
}
|
|
479
479
|
return binding
|
|
480
480
|
} catch (e) {
|
|
@@ -489,8 +489,8 @@ function requireNative() {
|
|
|
489
489
|
try {
|
|
490
490
|
const binding = require('@swc/anyformat-pdf-linux-s390x-gnu')
|
|
491
491
|
const bindingPackageVersion = require('@swc/anyformat-pdf-linux-s390x-gnu/package.json').version
|
|
492
|
-
if (bindingPackageVersion !== '0.
|
|
493
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
492
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
493
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
494
494
|
}
|
|
495
495
|
return binding
|
|
496
496
|
} catch (e) {
|
|
@@ -509,8 +509,8 @@ function requireNative() {
|
|
|
509
509
|
try {
|
|
510
510
|
const binding = require('@swc/anyformat-pdf-openharmony-arm64')
|
|
511
511
|
const bindingPackageVersion = require('@swc/anyformat-pdf-openharmony-arm64/package.json').version
|
|
512
|
-
if (bindingPackageVersion !== '0.
|
|
513
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
512
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
513
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
514
514
|
}
|
|
515
515
|
return binding
|
|
516
516
|
} catch (e) {
|
|
@@ -525,8 +525,8 @@ function requireNative() {
|
|
|
525
525
|
try {
|
|
526
526
|
const binding = require('@swc/anyformat-pdf-openharmony-x64')
|
|
527
527
|
const bindingPackageVersion = require('@swc/anyformat-pdf-openharmony-x64/package.json').version
|
|
528
|
-
if (bindingPackageVersion !== '0.
|
|
529
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
528
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
529
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
530
530
|
}
|
|
531
531
|
return binding
|
|
532
532
|
} catch (e) {
|
|
@@ -541,8 +541,8 @@ function requireNative() {
|
|
|
541
541
|
try {
|
|
542
542
|
const binding = require('@swc/anyformat-pdf-openharmony-arm')
|
|
543
543
|
const bindingPackageVersion = require('@swc/anyformat-pdf-openharmony-arm/package.json').version
|
|
544
|
-
if (bindingPackageVersion !== '0.
|
|
545
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
544
|
+
if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
545
|
+
throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
546
546
|
}
|
|
547
547
|
return binding
|
|
548
548
|
} catch (e) {
|
|
@@ -683,8 +683,8 @@ if (!nativeBinding || forceWasi) {
|
|
|
683
683
|
if (!candidateFailed) {
|
|
684
684
|
if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
685
685
|
const bindingPackageVersion = require('@swc/anyformat-pdf-wasm32-wasi/package.json').version
|
|
686
|
-
if (bindingPackageVersion !== '0.
|
|
687
|
-
throw new Error(`WASI binding package version mismatch, expected 0.
|
|
686
|
+
if (bindingPackageVersion !== '0.2.0') {
|
|
687
|
+
throw new Error(`WASI binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
688
688
|
}
|
|
689
689
|
}
|
|
690
690
|
wasiBinding = require('@swc/anyformat-pdf-wasm32-wasi')
|
|
@@ -836,4 +836,11 @@ function __napiStampBindingTarget(exportsObject, target) {
|
|
|
836
836
|
module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
|
|
837
837
|
module.exports = nativeBinding
|
|
838
838
|
module.exports.detectVersion = nativeBinding.detectVersion
|
|
839
|
+
module.exports.detectVersionFile = nativeBinding.detectVersionFile
|
|
840
|
+
module.exports.detectVersionFileSync = nativeBinding.detectVersionFileSync
|
|
841
|
+
module.exports.detectVersionSync = nativeBinding.detectVersionSync
|
|
842
|
+
module.exports.HEADER_PREFIX_LEN = nativeBinding.HEADER_PREFIX_LEN
|
|
839
843
|
module.exports.isPdf = nativeBinding.isPdf
|
|
844
|
+
module.exports.isPdfFile = nativeBinding.isPdfFile
|
|
845
|
+
module.exports.isPdfFileSync = nativeBinding.isPdfFileSync
|
|
846
|
+
module.exports.isPdfSync = nativeBinding.isPdfSync
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
1
|
// The public type definitions of @swc/anyformat-pdf. See index.js.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { ReadableStream } from 'node:stream/web'
|
|
4
|
+
|
|
5
|
+
export { detectVersionSync, isPdfSync } from './binding.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns `true` when `data` starts with a PDF file header, on the thread
|
|
9
|
+
* pool. Copies only the first 1031 bytes, so the caller can change `data`
|
|
10
|
+
* after the call.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isPdf(data: Uint8Array): Promise<boolean>
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Reads the version, for example `"1.7"`, from the PDF header of `data`, on
|
|
16
|
+
* the thread pool. Copies only the first 1031 bytes, so the caller can
|
|
17
|
+
* change `data` after the call.
|
|
18
|
+
*
|
|
19
|
+
* Returns `null` when the first 1024 bytes of `data` do not contain a PDF
|
|
20
|
+
* header.
|
|
21
|
+
*/
|
|
22
|
+
export declare function detectVersion(data: Uint8Array): Promise<string | null>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Reads the version, for example `"1.7"`, from the PDF header of the file at
|
|
26
|
+
* `path`, on the thread pool. Reads only the first 1031 bytes.
|
|
27
|
+
*
|
|
28
|
+
* Returns `null` when the first 1024 bytes of the file do not contain a PDF
|
|
29
|
+
* header. Rejects with an `Error` whose `code` is the errno name, for example
|
|
30
|
+
* `ENOENT`, when the file cannot be read.
|
|
31
|
+
*/
|
|
32
|
+
export declare function detectVersionFile(path: string | URL): Promise<string | null>
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Reads the version, for example `"1.7"`, from the PDF header of the file at
|
|
36
|
+
* `path`. Reads only the first 1031 bytes.
|
|
37
|
+
*
|
|
38
|
+
* Returns `null` when the first 1024 bytes of the file do not contain a PDF
|
|
39
|
+
* header.
|
|
40
|
+
*/
|
|
41
|
+
export declare function detectVersionFileSync(path: string | URL): string | null
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns `true` when the file at `path` starts with a PDF file header, on
|
|
45
|
+
* the thread pool. Reads only the first 1031 bytes.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isPdfFile(path: string | URL): Promise<boolean>
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Returns `true` when the file at `path` starts with a PDF file header.
|
|
51
|
+
* Reads only the first 1031 bytes.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isPdfFileSync(path: string | URL): boolean
|
|
54
|
+
|
|
55
|
+
/** The result of `isPdfStream`. */
|
|
56
|
+
export interface IsPdfStreamResult {
|
|
57
|
+
/** `true` when the input starts with a PDF file header. */
|
|
58
|
+
result: boolean
|
|
59
|
+
/** A stream that gives all of the bytes of the input. */
|
|
60
|
+
stream: ReadableStream<Uint8Array>
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Tells if a stream starts with a PDF file header. Reads chunks until it has
|
|
65
|
+
* 1031 bytes or the input ends.
|
|
66
|
+
*
|
|
67
|
+
* The returned `stream` gives all of the bytes of the input, including the
|
|
68
|
+
* bytes that the function read. Use it in place of the input stream.
|
|
69
|
+
*/
|
|
70
|
+
export declare function isPdfStream(
|
|
71
|
+
stream: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>,
|
|
72
|
+
): Promise<IsPdfStreamResult>
|
package/index.js
CHANGED
|
@@ -7,6 +7,22 @@
|
|
|
7
7
|
// packages will connect to the public API here.
|
|
8
8
|
|
|
9
9
|
const binding = require('./binding.js')
|
|
10
|
+
const { fileFunction, fileFunctionSync, streamFunction } = require('@swc/anyformat-utils')
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
const headerPrefixLen = () => binding.HEADER_PREFIX_LEN
|
|
13
|
+
|
|
14
|
+
// The native functions throw for an argument of a wrong type. An
|
|
15
|
+
// asynchronous function always returns a promise, so reject in that case.
|
|
16
|
+
module.exports.detectVersion = async function detectVersion(data) {
|
|
17
|
+
return binding.detectVersion(data)
|
|
18
|
+
}
|
|
19
|
+
module.exports.detectVersionSync = binding.detectVersionSync
|
|
20
|
+
module.exports.detectVersionFile = fileFunction(binding.detectVersionFile, binding)
|
|
21
|
+
module.exports.detectVersionFileSync = fileFunctionSync(binding.detectVersionFileSync, binding)
|
|
22
|
+
module.exports.isPdf = async function isPdf(data) {
|
|
23
|
+
return binding.isPdf(data)
|
|
24
|
+
}
|
|
25
|
+
module.exports.isPdfSync = binding.isPdfSync
|
|
26
|
+
module.exports.isPdfFile = fileFunction(binding.isPdfFile, binding)
|
|
27
|
+
module.exports.isPdfFileSync = fileFunctionSync(binding.isPdfFileSync, binding)
|
|
28
|
+
module.exports.isPdfStream = streamFunction(headerPrefixLen, binding.isPdfSync)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swc/anyformat-pdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "High-performance PDF processing for Node.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"armv7-unknown-linux-gnueabihf",
|
|
32
32
|
"aarch64-linux-android",
|
|
33
33
|
"armv7-linux-androideabi",
|
|
34
|
-
"x86_64-unknown-freebsd"
|
|
34
|
+
"x86_64-unknown-freebsd",
|
|
35
|
+
"wasm32-wasip1-threads"
|
|
35
36
|
]
|
|
36
37
|
},
|
|
37
38
|
"engines": {
|
|
@@ -40,23 +41,31 @@
|
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public"
|
|
42
43
|
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@swc/anyformat-utils": "0.2.0"
|
|
46
|
+
},
|
|
43
47
|
"devDependencies": {
|
|
44
|
-
"@
|
|
48
|
+
"@emnapi/core": "2.0.0-beta.3",
|
|
49
|
+
"@emnapi/runtime": "2.0.0-beta.3",
|
|
50
|
+
"@napi-rs/cli": "^3.11.1",
|
|
51
|
+
"@napi-rs/wasm-runtime": "^1.2.7",
|
|
52
|
+
"emnapi": "2.0.0-beta.3"
|
|
45
53
|
},
|
|
46
54
|
"optionalDependencies": {
|
|
47
|
-
"@swc/anyformat-pdf-darwin-x64": "0.
|
|
48
|
-
"@swc/anyformat-pdf-darwin-arm64": "0.
|
|
49
|
-
"@swc/anyformat-pdf-win32-x64-msvc": "0.
|
|
50
|
-
"@swc/anyformat-pdf-win32-arm64-msvc": "0.
|
|
51
|
-
"@swc/anyformat-pdf-win32-ia32-msvc": "0.
|
|
52
|
-
"@swc/anyformat-pdf-linux-x64-gnu": "0.
|
|
53
|
-
"@swc/anyformat-pdf-linux-arm64-gnu": "0.
|
|
54
|
-
"@swc/anyformat-pdf-linux-x64-musl": "0.
|
|
55
|
-
"@swc/anyformat-pdf-linux-arm64-musl": "0.
|
|
56
|
-
"@swc/anyformat-pdf-linux-arm-gnueabihf": "0.
|
|
57
|
-
"@swc/anyformat-pdf-android-arm64": "0.
|
|
58
|
-
"@swc/anyformat-pdf-android-arm-eabi": "0.
|
|
59
|
-
"@swc/anyformat-pdf-freebsd-x64": "0.
|
|
55
|
+
"@swc/anyformat-pdf-darwin-x64": "0.2.0",
|
|
56
|
+
"@swc/anyformat-pdf-darwin-arm64": "0.2.0",
|
|
57
|
+
"@swc/anyformat-pdf-win32-x64-msvc": "0.2.0",
|
|
58
|
+
"@swc/anyformat-pdf-win32-arm64-msvc": "0.2.0",
|
|
59
|
+
"@swc/anyformat-pdf-win32-ia32-msvc": "0.2.0",
|
|
60
|
+
"@swc/anyformat-pdf-linux-x64-gnu": "0.2.0",
|
|
61
|
+
"@swc/anyformat-pdf-linux-arm64-gnu": "0.2.0",
|
|
62
|
+
"@swc/anyformat-pdf-linux-x64-musl": "0.2.0",
|
|
63
|
+
"@swc/anyformat-pdf-linux-arm64-musl": "0.2.0",
|
|
64
|
+
"@swc/anyformat-pdf-linux-arm-gnueabihf": "0.2.0",
|
|
65
|
+
"@swc/anyformat-pdf-android-arm64": "0.2.0",
|
|
66
|
+
"@swc/anyformat-pdf-android-arm-eabi": "0.2.0",
|
|
67
|
+
"@swc/anyformat-pdf-freebsd-x64": "0.2.0",
|
|
68
|
+
"@swc/anyformat-pdf-wasm32-wasi": "0.2.0"
|
|
60
69
|
},
|
|
61
70
|
"scripts": {
|
|
62
71
|
"build": "napi build --platform --js binding.js --dts binding.d.ts --release",
|