chore: stop using NeDB to convert pack files to JSON
This commit is contained in:
parent
f38adb5e02
commit
986b743ab6
3 changed files with 15 additions and 140 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
import promises from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import Datastore from "@seald-io/nedb";
|
||||
|
||||
/**
|
||||
* Removes unwanted data from a pack entry
|
||||
|
@ -57,25 +56,20 @@ export async function convertJSONToPack(contents) {
|
|||
/**
|
||||
* Converts a pack file (NeDB) to a JSON string.
|
||||
* @param {string} filename The name of the pack file
|
||||
* @returns {Promise<string>} A promise that resolves to an array of the documents in the pack file
|
||||
* @returns {Promise<string>} A promise that resolves to JSON string representing the pack file
|
||||
*/
|
||||
function convertPackFileToJSON(filename) {
|
||||
const db = new Datastore({ filename, autoload: true });
|
||||
return new Promise((resolve, reject) => {
|
||||
db.find({}, (err, docs) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(
|
||||
JSON.stringify(
|
||||
docs.map((entry) => cleanPackEntry(entry)),
|
||||
undefined,
|
||||
4,
|
||||
) + "\n",
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
async function convertPackFileToJSON(filename) {
|
||||
const data = await promises.readFile(filename, { flag: "r", encoding: "utf-8" });
|
||||
return (
|
||||
JSON.stringify(
|
||||
data.split(/\r?\n/).flatMap((entry) => {
|
||||
if (entry === "") return [];
|
||||
return cleanPackEntry(JSON.parse(entry));
|
||||
}),
|
||||
undefined,
|
||||
4,
|
||||
) + "\n"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue