-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
30 lines (25 loc) · 973 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import fs from 'node:fs/promises';
import path from 'node:path';
import { Parser, NameRegistry } from '../';
class Document extends Map {}
async function unpickle(fname: string) {
const pkl = await fs.readFile(path.join(fname), 'binary');
const buffer = Buffer.from(pkl, 'binary');
const registry = new NameRegistry()
.register('pathlib', 'WindowsPath', (...args) => args.join('\\'))
.register('pathlib', 'PosixPath', (...args) => args.join('/'))
.register('langchain.schema', 'Document', Document);
const parser = new Parser({
nameResolver: registry,
unpicklingTypeOfDictionary: 'Map',
unpicklingTypeOfSet: 'Set',
});
return parser.parse(buffer);
}
const obj = await unpickle('wiki.pkl');
console.log(obj);
// const codePoints = Array.from(obj)
// .map((v) => v.codePointAt(0).toString(16))
// .map((hex) => '\\u' + hex.padStart(4, 0) + '')
// .join('');
// console.log(codePoints);