@gukhanmun/opendict-cdb 0.2.0-dev.92 → 0.2.0-dev.95

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 CHANGED
@@ -72,6 +72,12 @@ To get the package URL of a CDB binary, use the `*Url` constants:
72
72
  The `*Bytes()` helpers read the binary from disk using `node:fs/promises` if loaded from
73
73
  a `file:` URL (default for npm installations), and fall back to `fetch` for other protocols.
74
74
 
75
+ The bundled binaries ship gzip-compressed (the `*Url` constants point at
76
+ *\*.cdb.gz* files) to stay within the JSR per-file size limit. The `*Bytes()`
77
+ helpers inflate them transparently, so their return value is always the raw
78
+ CDB; only reach past them to the `*Url` constants if you intend to handle the
79
+ gzip yourself.
80
+
75
81
 
76
82
  Relation to `@gukhanmun/opendict-fst`
77
83
  -------------------------------------
Binary file
Binary file
Binary file
package/dist/index.d.ts CHANGED
@@ -53,13 +53,31 @@ interface FileDictionarySource {
53
53
  //#endregion
54
54
  //#region index.d.ts
55
55
 
56
- /** URL of the bundled Open Korean Dictionary 일반어 CDB binary. */
56
+ /**
57
+ * URL of the bundled Open Korean Dictionary 一般語 CDB binary.
58
+ *
59
+ * The bundled artifact is stored gzip-compressed (hence the `.cdb.gz`
60
+ * extension) to stay within registry per-file size limits;
61
+ * {@link opendictCdbBytes} inflates it transparently.
62
+ */
57
63
  declare const opendictGeneralCdbUrl: URL;
58
- /** URL of the bundled Open Korean Dictionary 북한어 CDB binary. */
64
+ /**
65
+ * URL of the bundled Open Korean Dictionary 北韓語 CDB binary.
66
+ *
67
+ * Stored gzip-compressed; {@link opendictCdbBytes} inflates it transparently.
68
+ */
59
69
  declare const opendictNorthKoreanCdbUrl: URL;
60
- /** URL of the bundled Open Korean Dictionary 방언 CDB binary. */
70
+ /**
71
+ * URL of the bundled Open Korean Dictionary 方言 CDB binary.
72
+ *
73
+ * Stored gzip-compressed; {@link opendictCdbBytes} inflates it transparently.
74
+ */
61
75
  declare const opendictDialectCdbUrl: URL;
62
- /** URL of the bundled Open Korean Dictionary 옛말 CDB binary. */
76
+ /**
77
+ * URL of the bundled Open Korean Dictionary 옛말 CDB binary.
78
+ *
79
+ * Stored gzip-compressed; {@link opendictCdbBytes} inflates it transparently.
80
+ */
63
81
  declare const opendictArchaicCdbUrl: URL;
64
82
  /**
65
83
  * Loads an Open Korean Dictionary CDB binary as raw bytes.
@@ -68,6 +86,12 @@ declare const opendictArchaicCdbUrl: URL;
68
86
  * Node.js, Deno, or Bun; in other runtimes (e.g. browsers) and for all
69
87
  * other schemes the bytes are retrieved with `fetch`.
70
88
  *
89
+ * The bundled binaries are stored gzip-compressed to stay within registry
90
+ * per-file size limits. Bytes that begin with the gzip magic number are
91
+ * therefore inflated transparently, so the returned value is always the raw
92
+ * CDB ready to hand to `load`; bytes that are not gzip-compressed are returned
93
+ * unchanged.
94
+ *
71
95
  * @param url Location of the CDB binary to read.
72
96
  * @returns The CDB binary as a `Uint8Array`.
73
97
  */
package/dist/index.js CHANGED
@@ -1,16 +1,57 @@
1
1
  //#region index.ts
2
- /** URL of the bundled Open Korean Dictionary 일반어 CDB binary. */
3
- const opendictGeneralCdbUrl = new URL("./general.cdb", import.meta.url);
4
- /** URL of the bundled Open Korean Dictionary 북한어 CDB binary. */
5
- const opendictNorthKoreanCdbUrl = new URL("./north-korean.cdb", import.meta.url);
6
- /** URL of the bundled Open Korean Dictionary 방언 CDB binary. */
7
- const opendictDialectCdbUrl = new URL("./dialect.cdb", import.meta.url);
8
- /** URL of the bundled Open Korean Dictionary 옛말 CDB binary. */
9
- const opendictArchaicCdbUrl = new URL("./archaic.cdb", import.meta.url);
2
+ /**
3
+ * URL of the bundled Open Korean Dictionary 一般語 CDB binary.
4
+ *
5
+ * The bundled artifact is stored gzip-compressed (hence the `.cdb.gz`
6
+ * extension) to stay within registry per-file size limits;
7
+ * {@link opendictCdbBytes} inflates it transparently.
8
+ */
9
+ const opendictGeneralCdbUrl = new URL("./general.cdb.gz", import.meta.url);
10
+ /**
11
+ * URL of the bundled Open Korean Dictionary 北韓語 CDB binary.
12
+ *
13
+ * Stored gzip-compressed; {@link opendictCdbBytes} inflates it transparently.
14
+ */
15
+ const opendictNorthKoreanCdbUrl = new URL("./north-korean.cdb.gz", import.meta.url);
16
+ /**
17
+ * URL of the bundled Open Korean Dictionary 方言 CDB binary.
18
+ *
19
+ * Stored gzip-compressed; {@link opendictCdbBytes} inflates it transparently.
20
+ */
21
+ const opendictDialectCdbUrl = new URL("./dialect.cdb.gz", import.meta.url);
22
+ /**
23
+ * URL of the bundled Open Korean Dictionary 옛말 CDB binary.
24
+ *
25
+ * Stored gzip-compressed; {@link opendictCdbBytes} inflates it transparently.
26
+ */
27
+ const opendictArchaicCdbUrl = new URL("./archaic.cdb.gz", import.meta.url);
10
28
  function canReadLocalFile() {
11
29
  const globals = globalThis;
12
30
  return globals.Deno !== void 0 || typeof globals.process?.versions?.bun === "string" || typeof globals.process?.versions?.node === "string";
13
31
  }
32
+ async function readBytes(url) {
33
+ if (url.protocol === "file:" && canReadLocalFile()) {
34
+ const buf = await (await import(
35
+ /* webpackIgnore: true */
36
+ "node:fs/promises"
37
+ )).readFile(url);
38
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
39
+ }
40
+ const response = await fetch(url);
41
+ if (!response.ok) throw new Error(`Failed to fetch opendict CDB: HTTP ${response.status}`);
42
+ return new Uint8Array(await response.arrayBuffer());
43
+ }
44
+ function isGzip(bytes) {
45
+ return bytes.length >= 2 && bytes[0] === 31 && bytes[1] === 139;
46
+ }
47
+ async function gunzip(bytes) {
48
+ const decompressor = new DecompressionStream("gzip");
49
+ const inflated = new Response(decompressor.readable).arrayBuffer();
50
+ const writer = decompressor.writable.getWriter();
51
+ await writer.write(bytes);
52
+ await writer.close();
53
+ return new Uint8Array(await inflated);
54
+ }
14
55
  /**
15
56
  * Loads an Open Korean Dictionary CDB binary as raw bytes.
16
57
  *
@@ -18,20 +59,18 @@ function canReadLocalFile() {
18
59
  * Node.js, Deno, or Bun; in other runtimes (e.g. browsers) and for all
19
60
  * other schemes the bytes are retrieved with `fetch`.
20
61
  *
62
+ * The bundled binaries are stored gzip-compressed to stay within registry
63
+ * per-file size limits. Bytes that begin with the gzip magic number are
64
+ * therefore inflated transparently, so the returned value is always the raw
65
+ * CDB ready to hand to `load`; bytes that are not gzip-compressed are returned
66
+ * unchanged.
67
+ *
21
68
  * @param url Location of the CDB binary to read.
22
69
  * @returns The CDB binary as a `Uint8Array`.
23
70
  */
24
71
  async function opendictCdbBytes(url) {
25
- if (url.protocol === "file:" && canReadLocalFile()) {
26
- const buf = await (await import(
27
- /* webpackIgnore: true */
28
- "node:fs/promises"
29
- )).readFile(url);
30
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
31
- }
32
- const response = await fetch(url);
33
- if (!response.ok) throw new Error(`Failed to fetch opendict CDB: HTTP ${response.status}`);
34
- return new Uint8Array(await response.arrayBuffer());
72
+ const bytes = await readBytes(url);
73
+ return isGzip(bytes) ? await gunzip(bytes) : bytes;
35
74
  }
36
75
  /**
37
76
  * Loads the bundled Open Korean Dictionary 일반어 CDB binary as raw bytes.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gukhanmun/opendict-cdb",
3
- "version": "0.2.0-dev.92",
3
+ "version": "0.2.0-dev.95",
4
4
  "description": "Open Korean Dictionary categories bundled as CDB binaries for @gukhanmun/wasm and @gukhanmun/napi.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -9,10 +9,10 @@
9
9
  "import": "./dist/index.js",
10
10
  "default": "./dist/index.js"
11
11
  },
12
- "./general.cdb": "./dist/general.cdb",
13
- "./north-korean.cdb": "./dist/north-korean.cdb",
14
- "./dialect.cdb": "./dist/dialect.cdb",
15
- "./archaic.cdb": "./dist/archaic.cdb"
12
+ "./general.cdb.gz": "./dist/general.cdb.gz",
13
+ "./north-korean.cdb.gz": "./dist/north-korean.cdb.gz",
14
+ "./dialect.cdb.gz": "./dist/dialect.cdb.gz",
15
+ "./archaic.cdb.gz": "./dist/archaic.cdb.gz"
16
16
  },
17
17
  "files": [
18
18
  "ATTRIBUTION.md",
@@ -52,10 +52,10 @@
52
52
  "@gukhanmun/types": "*"
53
53
  },
54
54
  "devDependencies": {
55
- "@gukhanmun/types": "0.2.0-dev.92+fbba03eee35ae4ce2eec88cff540c36edbfd95be"
55
+ "@gukhanmun/types": "0.2.0-dev.95+55f6a6bbeef32ec3557c503b9e0c4c94cf2e2917"
56
56
  },
57
57
  "scripts": {
58
58
  "prebuild": "mise run -C ../.. opendict-cdb-data",
59
- "build": "tsdown && node -e \"const fs=require('node:fs');fs.mkdirSync('dist',{recursive:true});for(const f of ['general.cdb','north-korean.cdb','dialect.cdb','archaic.cdb'])fs.copyFileSync(f,'dist/'+f)\""
59
+ "build": "tsdown && node -e \"const fs=require('node:fs');fs.mkdirSync('dist',{recursive:true});for(const f of ['general.cdb.gz','north-korean.cdb.gz','dialect.cdb.gz','archaic.cdb.gz'])fs.copyFileSync(f,'dist/'+f)\""
60
60
  }
61
61
  }
package/dist/archaic.cdb DELETED
Binary file
package/dist/dialect.cdb DELETED
Binary file
package/dist/general.cdb DELETED
Binary file
Binary file