Skip to content

Commit

Permalink
fix: cache arrayBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Jan 6, 2024
1 parent 91aace8 commit d195b54
Show file tree
Hide file tree
Showing 5 changed files with 500 additions and 448 deletions.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.14.0
v18.19.0
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@
"lru_map": "^0.4.1"
},
"devDependencies": {
"@types/mocha": "^10.0.1",
"@types/node": "^18.13.0",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.6",
"cross-env": "^7.0.3",
"lint-staged": "^13.1.1",
"lint-staged": "^15.2.0",
"mocha": "^10.2.0",
"node-stdlib-browser": "^1.2.0",
"prettier": "^2.8.4",
"ts-node": "^10.9.1",
"prettier": "^3.1.1",
"tiny-compressor": "^1.0.1",
"ts-node": "^10.9.2",
"ts-node-test-register": "^10.0.0",
"typescript": "^4.9.5",
"vite": "^4.1.1",
"vite-plugin-node-stdlib-browser": "^0.1.1",
"tiny-compressor": "^1.0.0"
"typescript": "^5.3.3",
"vite": "^5.0.11",
"vite-plugin-node-stdlib-browser": "^0.2.1"
},
"email": "azuciao@gmail.com",
"prettier": {
Expand Down
2 changes: 0 additions & 2 deletions vite.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as path from "node:path";
import nodePolyfills from 'vite-plugin-node-stdlib-browser'
const __dirname = path.dirname(new URL(import.meta.url).pathname);
export default {
plugins: [nodePolyfills()]
};
15 changes: 11 additions & 4 deletions web/kuromoji.patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class Deferred {
BrowserDictionaryLoader.prototype.loadArrayBuffer = async function (url, callback) {
const stroage = await kvsEnvStorage({
name: "kuromoji",
version: 1
version: 2,
upgrade({ kvs, oldVersion, newVersion }) {
if (oldVersion === 1) {
kvs.clear();
}
}
});
// https://github.com/takuyaa/kuromoji.js/issues/37
const fixedURL = url.replace("https:/", "https://");
Expand Down Expand Up @@ -51,10 +56,12 @@ BrowserDictionaryLoader.prototype.loadArrayBuffer = async function (url, callbac
return callback(response.statusText, null);
}
const arraybuffer = await response.arrayBuffer();
// decomparess gzipped dictionary
const typedArray = await Compressor.decompress(new Uint8Array(arraybuffer), "gzip");
return stroage.set(fixedURL, typedArray).then(() => {
deferred.resolve(typedArray);
callback(null, typedArray);
const decompressedArrayBuffer = typedArray.buffer;
return stroage.set(fixedURL, decompressedArrayBuffer).then(() => {
deferred.resolve(decompressedArrayBuffer);
callback(null, decompressedArrayBuffer);
});
})
.catch(function (exception) {
Expand Down
Loading

0 comments on commit d195b54

Please sign in to comment.